From ef412c0b9031aac291541265db81601aea95c4d5 Mon Sep 17 00:00:00 2001 From: 1234tgk <1234tgk@gmail.com> Date: Mon, 8 May 2023 16:18:20 -0400 Subject: [PATCH 1/2] add check script --- code/addons/storyshots-core/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/code/addons/storyshots-core/package.json b/code/addons/storyshots-core/package.json index 0d3c3eb071ae..e8cebec39fd2 100644 --- a/code/addons/storyshots-core/package.json +++ b/code/addons/storyshots-core/package.json @@ -32,6 +32,7 @@ "*.d.ts" ], "scripts": { + "check": "../../../scripts/node_modules/.bin/tsc --noEmit", "prep": "../../../scripts/prepare/tsc.ts" }, "dependencies": { From a170b64d726914e8c6ef5140e88cfb26fd371dba Mon Sep 17 00:00:00 2001 From: 1234tgk <1234tgk@gmail.com> Date: Wed, 10 May 2023 02:49:10 -0400 Subject: [PATCH 2/2] convert to strict TS --- .../storyshots-core/src/Stories2SnapsConverter.test.ts | 6 +++--- code/addons/storyshots-core/src/Stories2SnapsConverter.ts | 2 +- code/addons/storyshots-core/src/api/StoryshotsOptions.ts | 2 +- code/addons/storyshots-core/src/api/index.ts | 4 ++-- code/addons/storyshots-core/src/frameworks/configure.ts | 2 +- .../storyshots-core/src/frameworks/frameworkLoader.ts | 2 +- code/addons/storyshots-core/tsconfig.json | 2 +- .../angular/src/client/angular-beta/StorybookModule.ts | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/code/addons/storyshots-core/src/Stories2SnapsConverter.test.ts b/code/addons/storyshots-core/src/Stories2SnapsConverter.test.ts index d066d1226e58..916ee94eb34c 100644 --- a/code/addons/storyshots-core/src/Stories2SnapsConverter.test.ts +++ b/code/addons/storyshots-core/src/Stories2SnapsConverter.test.ts @@ -7,7 +7,7 @@ describe('getSnapshotFileName', () => { const context = { fileName: 'foo.js', kind: 'kind' }; const result = target.getSnapshotFileName(context); - const platformAgnosticResult = result.replace(/\\|\//g, '/'); + const platformAgnosticResult = result?.replace(/\\|\//g, '/'); // This is an absolute path, so we need to use `toContain()` expect(platformAgnosticResult).toContain('__snapshots__/foo.storyshot'); @@ -17,7 +17,7 @@ describe('getSnapshotFileName', () => { const context = { fileName: 'foo.web.stories.js', kind: 'kind' }; const result = target.getSnapshotFileName(context); - const platformAgnosticResult = result.replace(/\\|\//g, '/'); + const platformAgnosticResult = result?.replace(/\\|\//g, '/'); // This is an absolute path, so we need to use `toContain()` expect(platformAgnosticResult).toContain('__snapshots__/foo.web.stories.storyshot'); @@ -27,7 +27,7 @@ describe('getSnapshotFileName', () => { const context = { fileName: 'test/foo.js', kind: 'kind' }; const result = target.getSnapshotFileName(context); - const platformAgnosticResult = result.replace(/\\|\//g, '/'); + const platformAgnosticResult = result?.replace(/\\|\//g, '/'); // This is an absolute path, so we need to use `toContain()` expect(platformAgnosticResult).toContain('test/__snapshots__/foo.storyshot'); diff --git a/code/addons/storyshots-core/src/Stories2SnapsConverter.ts b/code/addons/storyshots-core/src/Stories2SnapsConverter.ts index 439a514f7bd4..4d6788e6b278 100644 --- a/code/addons/storyshots-core/src/Stories2SnapsConverter.ts +++ b/code/addons/storyshots-core/src/Stories2SnapsConverter.ts @@ -55,7 +55,7 @@ export class Stories2SnapsConverter { } ` ); - return null; + return undefined; } return this.getStoryshotFile(fileName); diff --git a/code/addons/storyshots-core/src/api/StoryshotsOptions.ts b/code/addons/storyshots-core/src/api/StoryshotsOptions.ts index 0dc34d1ef24e..cbc853717de3 100644 --- a/code/addons/storyshots-core/src/api/StoryshotsOptions.ts +++ b/code/addons/storyshots-core/src/api/StoryshotsOptions.ts @@ -9,7 +9,7 @@ export interface TestMethodOptions { renderTree: RenderTree; renderShallowTree: RenderTree; stories2snapsConverter: Stories2SnapsConverter; - snapshotFileName: string; + snapshotFileName?: string; options: any; done?: () => void; } diff --git a/code/addons/storyshots-core/src/api/index.ts b/code/addons/storyshots-core/src/api/index.ts index 301d5cbf8c36..932d728a6345 100644 --- a/code/addons/storyshots-core/src/api/index.ts +++ b/code/addons/storyshots-core/src/api/index.ts @@ -54,7 +54,7 @@ function testStorySnapshots(options: StoryshotsOptions = {}) { // subsequent calls to `it()` etc will all happen within this tick, which is required // by Jest (cannot add tests asynchronously) globalWindow.__STORYBOOK_STORY_STORE__.initializationPromise.then(() => { - const data = storybook.raw().reduce( + const data = storybook.raw()?.reduce( (acc, item) => { if (storyNameRegex && !item.name.match(storyNameRegex)) { return acc; @@ -86,7 +86,7 @@ function testStorySnapshots(options: StoryshotsOptions = {}) { }[] ); - if (data.length) { + if (data && data.length) { callTestMethodGlobals(testMethod); snapshotsTests({ diff --git a/code/addons/storyshots-core/src/frameworks/configure.ts b/code/addons/storyshots-core/src/frameworks/configure.ts index aa1a1733c776..bdc39e73454f 100644 --- a/code/addons/storyshots-core/src/frameworks/configure.ts +++ b/code/addons/storyshots-core/src/frameworks/configure.ts @@ -74,7 +74,7 @@ function getConfigPathParts(input: string): Output { return specifier; }); - output.requireContexts = output.stories.map((specifier) => { + output.requireContexts = output.stories?.map((specifier) => { const { path: basePath, recursive, match } = toRequireContext(specifier); // eslint-disable-next-line no-underscore-dangle diff --git a/code/addons/storyshots-core/src/frameworks/frameworkLoader.ts b/code/addons/storyshots-core/src/frameworks/frameworkLoader.ts index 6589df427390..40fbed19b2a3 100644 --- a/code/addons/storyshots-core/src/frameworks/frameworkLoader.ts +++ b/code/addons/storyshots-core/src/frameworks/frameworkLoader.ts @@ -28,7 +28,7 @@ function getLoaders(): Loader[] { return null; }) .filter(Boolean) - .map((loader) => require(loader).default); + .map((loader) => loader && require(loader).default); } function loadFramework(options: StoryshotsOptions) { diff --git a/code/addons/storyshots-core/tsconfig.json b/code/addons/storyshots-core/tsconfig.json index be122d9916a4..6d43397802f1 100644 --- a/code/addons/storyshots-core/tsconfig.json +++ b/code/addons/storyshots-core/tsconfig.json @@ -5,7 +5,7 @@ "jsx": "preserve", "skipLibCheck": true, "skipDefaultLibCheck": true, - "strict": false + "strict": true }, "include": ["src/**/*.ts"] } diff --git a/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts b/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts index 3535a85c6988..f4c01547b734 100644 --- a/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts +++ b/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts @@ -12,7 +12,7 @@ export const getApplication = ({ storyFnAngular: StoryFnAngularReturnType; component?: any; targetSelector: string; - analyzedMetadata: PropertyExtractor; + analyzedMetadata?: PropertyExtractor; }) => { const { props, styles, moduleMetadata = {} } = storyFnAngular; let { template } = storyFnAngular;