diff --git a/code/jest.config.js b/code/jest.config.js index ef5b43abe791..b822679c5d70 100644 --- a/code/jest.config.js +++ b/code/jest.config.js @@ -1,21 +1,17 @@ const os = require('os'); -// TODO Revisit this test later, when we have a windows machine @valentinpalkovic +/** + * TODO: Some windows related tasks are still commented out, because they are behaving differently on + * a local Windows machine compared to the Windows Server 2022 machine running in GitHub Actions. + * The main issue is that path.sep is behaving differently on the two machines. Some more investagations + * are necessary! + * */ const skipOnWindows = [ - 'lib/core-server/src/utils/stories-json.test.ts', - 'lib/core-server/src/utils/StoryIndexGenerator.test.ts', - 'lib/cli/src/helpers.test.ts', 'lib/core-server/src/utils/__tests__/server-statics.test.ts', 'lib/core-common/src/utils/__tests__/template.test.ts', 'addons/storyshots/storyshots-core/src/frameworks/configure.test.ts', 'lib/core-common/src/utils/__tests__/interpret-files.test.ts', - 'lib/builder-manager/src/utils/files.test.ts', 'lib/cli/src/helpers.test.ts', - 'lib/core-server/src/utils/__tests__/server-statics.test.ts', - 'lib/core-common/src/utils/__tests__/template.test.ts', - 'addons/storyshots/storyshots-core/src/frameworks/configure.test.ts', - 'lib/core-common/src/utils/__tests__/interpret-files.test.ts', - 'lib/builder-manager/src/utils/files.test.ts', ]; module.exports = { diff --git a/code/lib/builder-manager/src/utils/files.test.ts b/code/lib/builder-manager/src/utils/files.test.ts index 41d62ec82693..2cdb1f0d4c59 100644 --- a/code/lib/builder-manager/src/utils/files.test.ts +++ b/code/lib/builder-manager/src/utils/files.test.ts @@ -1,17 +1,27 @@ +import { platform } from 'os'; import { sanitizePath } from './files'; +const os = platform(); +const isWindows = os === 'win32'; + test('sanitizePath', () => { - const addonsDir = '/Users/username/Projects/projectname/storybook'; + const addonsDir = isWindows + ? 'C:\\Users\\username\\Projects\\projectname\\storybook' + : '/Users/username/Projects/projectname/storybook'; const text = 'demo text'; const file = { - path: '/Users/username/Projects/projectname/storybook/node_modules/@storybook/addon-x+y/dist/manager.mjs', + path: isWindows + ? 'C:\\Users\\username\\Projects\\projectname\\storybook\\node_modules\\@storybook\\addon-x+y\\dist\\manager.mjs' + : '/Users/username/Projects/projectname/storybook/node_modules/@storybook/addon-x+y/dist/manager.mjs', contents: Uint8Array.from(Array.from(text).map((letter) => letter.charCodeAt(0))), text, }; const { location, url } = sanitizePath(file, addonsDir); - expect(location).toMatchInlineSnapshot( - `"/Users/username/Projects/projectname/storybook/node_modules/@storybook/addon-x+y/dist/manager.mjs"` + expect(location).toEqual( + isWindows + ? 'C:\\Users\\username\\Projects\\projectname\\storybook\\node_modules\\@storybook\\addon-x+y\\dist\\manager.mjs' + : '/Users/username/Projects/projectname/storybook/node_modules/@storybook/addon-x+y/dist/manager.mjs' ); expect(url).toMatchInlineSnapshot( `"./sb-addons/node_modules/%40storybook/addon-x%2By/dist/manager.mjs"` diff --git a/code/lib/builder-manager/src/utils/files.ts b/code/lib/builder-manager/src/utils/files.ts index bded035f9a2c..bca197dcda9e 100644 --- a/code/lib/builder-manager/src/utils/files.ts +++ b/code/lib/builder-manager/src/utils/files.ts @@ -1,6 +1,6 @@ import type { OutputFile } from 'esbuild'; import fs from 'fs-extra'; -import { join } from 'path'; +import { join, normalize } from 'path'; import slash from 'slash'; import type { Compilation } from '../types'; @@ -26,7 +26,8 @@ export async function readOrderedFiles( export function sanitizePath(file: OutputFile, addonsDir: string) { const filePath = file.path.replace(addonsDir, ''); - const location = join(addonsDir, filePath); + const location = normalize(join(addonsDir, filePath)); const url = `./sb-addons${slash(filePath).split('/').map(encodeURIComponent).join('/')}`; + return { location, url }; } diff --git a/code/lib/cli/src/helpers.ts b/code/lib/cli/src/helpers.ts index 00ebb767831f..53bfc848077d 100644 --- a/code/lib/cli/src/helpers.ts +++ b/code/lib/cli/src/helpers.ts @@ -198,6 +198,7 @@ export async function copyComponents( const componentsPath = async () => { const baseDir = getRendererDir(renderer); const assetsDir = join(baseDir, 'template/cli'); + const assetsLanguage = join(assetsDir, languageFolderMapping[language]); const assetsJS = join(assetsDir, languageFolderMapping[SupportedLanguage.JAVASCRIPT]); const assetsTSLegacy = join( @@ -232,7 +233,9 @@ export async function copyComponents( }; const destinationPath = await targetPath(); - await fse.copy(join(getCliDir(), 'rendererAssets/common'), destinationPath, { overwrite: true }); + await fse.copy(join(getCliDir(), 'rendererAssets/common'), destinationPath, { + overwrite: true, + }); await fse.copy(await componentsPath(), destinationPath, { overwrite: true }); } diff --git a/code/lib/core-client/src/PreviewWeb.mockdata.ts b/code/lib/core-client/src/PreviewWeb.mockdata.ts index e176aecc069c..4bcd742107ea 100644 --- a/code/lib/core-client/src/PreviewWeb.mockdata.ts +++ b/code/lib/core-client/src/PreviewWeb.mockdata.ts @@ -173,9 +173,9 @@ export const waitForEvents = ( events.forEach((event) => mockChannel.on(event, listener)); // Don't wait too long - waitForQuiescence().then(() => - reject(new Error(`Event was not emitted in time: ${debugLabel || events}`)) - ); + waitForQuiescence().then(() => { + reject(new Error(`Event was not emitted in time: ${debugLabel || events}`)); + }); }); }; diff --git a/code/lib/core-common/package.json b/code/lib/core-common/package.json index bac9dfabcd21..bf644545c3c3 100644 --- a/code/lib/core-common/package.json +++ b/code/lib/core-common/package.json @@ -73,9 +73,9 @@ "util-deprecate": "^1.0.2" }, "devDependencies": { - "@types/mock-fs": "^4.13.0", + "@types/mock-fs": "^4.13.1", "@types/picomatch": "^2.3.0", - "mock-fs": "^4.13.0", + "mock-fs": "^5.2.0", "type-fest": "^2.17.0", "typescript": "~4.6.3" }, diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts index 676abe654994..b70a4838e009 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -1176,30 +1176,6 @@ describe('StoryIndexGenerator', () => { expect(Object.keys((await generator.getIndex()).entries)).not.toContain('notitle--docs'); }); - it('errors on dependency deletion', async () => { - const storiesSpecifier: CoreCommon_NormalizedStoriesSpecifier = normalizeStoriesEntry( - './src/A.stories.(ts|js|jsx)', - options - ); - const docsSpecifier: CoreCommon_NormalizedStoriesSpecifier = normalizeStoriesEntry( - './src/docs2/*.mdx', - options - ); - - const generator = new StoryIndexGenerator([docsSpecifier, storiesSpecifier], options); - await generator.initialize(); - await generator.getIndex(); - expect(toId).toHaveBeenCalledTimes(5); - - expect(Object.keys((await generator.getIndex()).entries)).toContain('a--story-one'); - - generator.invalidate(storiesSpecifier, './src/A.stories.js', true); - - await expect(() => generator.getIndex()).rejects.toThrowError( - /Could not find "..\/A.stories" for docs file/ - ); - }); - it('cleans up properly on dependent docs deletion', async () => { const storiesSpecifier: CoreCommon_NormalizedStoriesSpecifier = normalizeStoriesEntry( './src/A.stories.(ts|js|jsx)', diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index 2d8f3d4c5180..d6a4be5afea9 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -304,7 +304,12 @@ export class StoryIndexGenerator { dependencies.forEach((dep) => { if (dep.entries.length > 0) { const first = dep.entries[0]; - if (path.resolve(this.options.workingDir, first.importPath).startsWith(absoluteOf)) { + + if ( + path + .normalize(path.resolve(this.options.workingDir, first.importPath)) + .startsWith(path.normalize(absoluteOf)) + ) { ofTitle = first.title; } } @@ -485,11 +490,6 @@ export class StoryIndexGenerator { } }); }); - - const notFound = dependents.filter((dep) => !invalidated.has(dep)); - if (notFound.length > 0) { - throw new Error(`Could not invalidate ${notFound.length} deps: ${notFound.join(', ')}`); - } } if (removed) { diff --git a/code/yarn.lock b/code/yarn.lock index bf1a81e7a531..b6ea738efa7a 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6469,7 +6469,7 @@ __metadata: "@storybook/types": 7.0.0-alpha.49 "@types/babel__core": ^7.0.0 "@types/express": ^4.7.0 - "@types/mock-fs": ^4.13.0 + "@types/mock-fs": ^4.13.1 "@types/node": ^16.0.0 "@types/picomatch": ^2.3.0 "@types/pretty-hrtime": ^1.0.0 @@ -6483,7 +6483,7 @@ __metadata: glob: ^7.1.6 handlebars: ^4.7.7 lazy-universal-dotenv: ^3.0.1 - mock-fs: ^4.13.0 + mock-fs: ^5.2.0 picomatch: ^2.3.0 pkg-dir: ^5.0.0 pretty-hrtime: ^1.0.3 @@ -8787,7 +8787,7 @@ __metadata: languageName: node linkType: hard -"@types/mock-fs@npm:^4.13.0": +"@types/mock-fs@npm:^4.13.1": version: 4.13.1 resolution: "@types/mock-fs@npm:4.13.1" dependencies: @@ -25893,10 +25893,10 @@ __metadata: languageName: node linkType: hard -"mock-fs@npm:^4.13.0": - version: 4.14.0 - resolution: "mock-fs@npm:4.14.0" - checksum: a23bc2ce74f2a01d02053fb20aecc2ea359e62580cd15b5e1029b55929802e2770bbd683ccdc5c1eabb5cecbf452196bb81a0ef61c4629dc819023e10d8303c6 +"mock-fs@npm:^5.2.0": + version: 5.2.0 + resolution: "mock-fs@npm:5.2.0" + checksum: e917e71295ee9d805c7d9ab0214a66658db0212f35731ba0c75dc1ccbb9964e6787a6d725561f05fcf569c64cf4a1176f5ce438f98b009227520f646f8abf174 languageName: node linkType: hard