Skip to content

Commit

Permalink
Merge branch 'main' into fix-module-path-lint-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thafryer committed May 7, 2024
2 parents e76410f + da800dd commit ccf2f54
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,15 @@
# v11.3.1 (Tue May 07 2024)

#### 🐛 Bug Fix

- Properly check `storybookBaseDir` against repository root rather than CWD [#974](https://github.com/chromaui/chromatic-cli/pull/974) ([@ghengeveld](https://github.com/ghengeveld))

#### Authors: 1

- Gert Hengeveld ([@ghengeveld](https://github.com/ghengeveld))

---

# v11.3.0 (Fri Mar 29 2024)

#### 🚀 Enhancement
Expand Down
29 changes: 21 additions & 8 deletions node-src/lib/checkStorybookBaseDir.test.ts
@@ -1,8 +1,21 @@
import { describe, expect, it } from 'vitest';
import { checkStorybookBaseDir } from './checkStorybookBaseDir';
import path from 'path';
import TestLogger from './testLogger';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import * as git from '../git/git';
import { checkStorybookBaseDir } from './checkStorybookBaseDir';
import { exitCodes } from './setExitCode';
import TestLogger from './testLogger';

vi.mock('../git/git');

const getRepositoryRoot = vi.mocked(git.getRepositoryRoot);

beforeEach(() => {
getRepositoryRoot.mockResolvedValue(path.join(__dirname, '../__mocks__'));
});
afterEach(() => {
getRepositoryRoot.mockReset();
});

const getContext: any = (storybookBaseDir?: string) => ({
log: new TestLogger(),
Expand All @@ -11,7 +24,7 @@ const getContext: any = (storybookBaseDir?: string) => ({

describe('checkStorybookBaseDir', () => {
it('should return if a js(x)/ts(x) module in stats exists at the path prepended by the storybookBaseDir', async () => {
const ctx = getContext(path.join(__dirname, '../__mocks__/storybookBaseDir'));
const ctx = getContext('storybookBaseDir');

const statsWithJsModule = {
modules: [
Expand Down Expand Up @@ -64,7 +77,7 @@ describe('checkStorybookBaseDir', () => {
],
};

const ctxWithBaseDir = getContext(path.join(__dirname, '../__mocks__/wrong'));
const ctxWithBaseDir = getContext('wrong');
await expect(() => checkStorybookBaseDir(ctxWithBaseDir, stats)).rejects.toThrow();
expect(ctxWithBaseDir.exitCode).toBe(exitCodes.INVALID_OPTIONS);

Expand All @@ -74,12 +87,12 @@ describe('checkStorybookBaseDir', () => {
});

it('should not consider modules in node_modules as valid files to match', async () => {
const ctx = getContext(path.join(__dirname, '../../'));
const ctx = getContext('../..');
const stats = {
modules: [
{
id: './node_modules/@storybook/core-client/dist/esm/globals/polyfills.js',
name: './node_modules/@storybook/core-client/dist/esm/globals/polyfills.js',
id: './node_modules/env-ci/index.js',
name: './node_modules/env-ci/index.js',
},
],
};
Expand Down
6 changes: 4 additions & 2 deletions node-src/lib/checkStorybookBaseDir.ts
Expand Up @@ -4,10 +4,12 @@ import { invalidStorybookBaseDir } from '../ui/messages/errors/invalidStorybookB
import { Context, Stats } from '../types';
import pLimit from 'p-limit';
import { exitCodes, setExitCode } from './setExitCode';
import { getRepositoryRoot } from '../git/git';

export async function checkStorybookBaseDir(ctx: Context, stats: Stats) {
const repositoryRoot = await getRepositoryRoot();
const { storybookBaseDir = '' } = ctx.options;
ctx.log.debug('Storybook base directory:', storybookBaseDir);
ctx.log.debug('Storybook base directory:', path.join(repositoryRoot, storybookBaseDir));

// Find all js(x)/ts(x) files in stats that are not in node_modules
const sourceModuleFiles = stats.modules.filter(
Expand All @@ -22,7 +24,7 @@ export async function checkStorybookBaseDir(ctx: Context, stats: Stats) {
await Promise.any(
sourceModuleFiles.map((file) => {
return limitConcurrency(() => {
const absolutePath = path.join(storybookBaseDir, file.name);
const absolutePath = path.join(repositoryRoot, storybookBaseDir, file.name);
return new Promise((resolve, reject) =>
fs.access(absolutePath, (err) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "chromatic",
"version": "11.3.0",
"version": "11.3.1",
"description": "Automate visual testing across browsers. Gather UI feedback. Versioned documentation.",
"keywords": [
"storybook-addon",
Expand Down

0 comments on commit ccf2f54

Please sign in to comment.