Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech: TypeScript should check stories and tests as well #19831

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist
lib/**/dll
build
coverage
node_modules
Expand Down
10 changes: 1 addition & 9 deletions code/addons/actions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@
"compilerOptions": {
"strict": true
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/backgrounds/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/controls/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@
"compilerOptions": {
"strict": true
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
9 changes: 1 addition & 8 deletions code/addons/docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
"compilerOptions": {
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/essentials/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@
"compilerOptions": {
"strict": true
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/highlight/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@
"rootDir": "./src",
"types": ["webpack-env"]
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/interactions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
1 change: 0 additions & 1 deletion code/addons/links/src/react/components/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jest.mock('global', () => ({
search: 'search',
},
},
// @ts-expect-error (Converted from ts-ignore)
window: global,
__STORYBOOK_STORY_STORE__: {
fromId: jest.fn(() => ({})),
Expand Down
3 changes: 1 addition & 2 deletions code/addons/links/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { linkTo, hrefTo } from './utils';

jest.mock('@storybook/addons');
jest.mock('global', () => ({
// @ts-expect-error (Converted from ts-ignore)
document: global.document,
// @ts-expect-error (Converted from ts-ignore)
window: global,
}));

Expand Down Expand Up @@ -41,6 +39,7 @@ describe('preview', () => {

it('should select the story (only) provided', () => {
// simulate a currently selected, but not found as ID
// @ts-expect-error (not strict)
const handler = linkTo(undefined, 'name');
handler();

Expand Down
10 changes: 1 addition & 9 deletions code/addons/links/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@
"compilerOptions": {
"strict": true
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/measure/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
10 changes: 1 addition & 9 deletions code/addons/outline/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function integrityTest(integrityOptions: any, stories2snapsConverter: any) {
const snapshotExtension = stories2snapsConverter.getSnapshotExtension();
const storyshots = glob.sync(`**/*${snapshotExtension}`, integrityOptions);

// @ts-expect-error (Converted from ts-ignore)
expect(storyshots).notToBeAbandoned(stories2snapsConverter);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,35 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
setupAngularJestPreset();

const storybook = jest.requireActual('@storybook/angular');
const clientAPI = jest.requireActual('@storybook/client-api');
let mockStartedAPI: any;

const api = {
...clientAPI,
...storybook,
};
jest.mock('@storybook/core-client', () => {
const coreClientAPI = jest.requireActual('@storybook/core-client');

return {
...coreClientAPI,
start: (...args: any[]) => {
mockStartedAPI = coreClientAPI.start(...args);
return mockStartedAPI;
},
};
});

jest.mock('@storybook/angular', () => {
const renderAPI = jest.requireActual('@storybook/angular');

renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator;
renderAPI.addParameters = mockStartedAPI.clientApi.addParameters;

return renderAPI;
});

// eslint-disable-next-line global-require
const storybook = require('@storybook/angular');

configure({
...options,
storybook: api,
storybook,
});

return {
Expand All @@ -52,7 +70,7 @@ function load(options: StoryshotsOptions) {
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for angular');
},
storybook: api,
storybook,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,35 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'html';

const storybook = jest.requireActual('@storybook/html');
const clientAPI = jest.requireActual('@storybook/client-api');
let mockStartedAPI: any;

jest.mock('@storybook/core-client', () => {
const coreClientAPI = jest.requireActual('@storybook/core-client');

return {
...coreClientAPI,
start: (...args: any[]) => {
mockStartedAPI = coreClientAPI.start(...args);
return mockStartedAPI;
},
};
});

const api = {
...clientAPI,
...storybook,
};
jest.mock('@storybook/html', () => {
const renderAPI = jest.requireActual('@storybook/html');

renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator;
renderAPI.addParameters = mockStartedAPI.clientApi.addParameters;

return renderAPI;
});

// eslint-disable-next-line global-require
const storybook = require('@storybook/html');

configure({
...options,
storybook: api,
storybook,
});

return {
Expand All @@ -29,7 +47,7 @@ function load(options: StoryshotsOptions) {
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for HTML');
},
storybook: api,
storybook,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,35 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'preact';

const storybook = jest.requireActual('@storybook/preact');
const clientAPI = jest.requireActual('@storybook/client-api');
let mockStartedAPI: any;

const api = {
...clientAPI,
...storybook,
};
jest.mock('@storybook/core-client', () => {
const coreClientAPI = jest.requireActual('@storybook/core-client');

return {
...coreClientAPI,
start: (...args: any[]) => {
mockStartedAPI = coreClientAPI.start(...args);
return mockStartedAPI;
},
};
});

jest.mock('@storybook/preact', () => {
const renderAPI = jest.requireActual('@storybook/preact');

renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator;
renderAPI.addParameters = mockStartedAPI.clientApi.addParameters;

return renderAPI;
});

// eslint-disable-next-line global-require
const storybook = require('@storybook/preact');

configure({
...options,
storybook: api,
storybook,
});

return {
Expand All @@ -35,7 +53,7 @@ function load(options: StoryshotsOptions) {
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for preact');
},
storybook: api,
storybook,
};
}

Expand Down
Loading