Skip to content

Commit

Permalink
Merge branch 'improve-types' into improve-test-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjtc committed Nov 10, 2023
2 parents 916c55a + c7b4bed commit a6179ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
15 changes: 8 additions & 7 deletions src/config/jest-playwright.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from 'path';

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / release

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / release

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / typecheck

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / typecheck

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / typecheck

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / typecheck

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Duplicate identifier 'Config'.

Check failure on line 1 in src/config/jest-playwright.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Duplicate identifier 'Config'.
import type { Config } from '@jest/types';
import { getProjectRoot } from '@storybook/core-common';
import type { Config } from '@jest/types';

const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH || '@storybook/test-runner';
const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/test-runner';

/**
* IMPORTANT NOTE:
Expand All @@ -29,11 +30,11 @@ const getJestPlaywrightConfig = (): Config.InitialOptions => {
);
return {
runner: path.join(presetBasePath, 'runner.js'),
globalSetup: require.resolve(TEST_RUNNER_PATH + '/dist/templates/global-setup'),
globalTeardown: require.resolve(TEST_RUNNER_PATH + '/dist/templates/global-teardown'),
testEnvironment: require.resolve(TEST_RUNNER_PATH + '/dist/templates/custom-environment'),
globalSetup: require.resolve(`${TEST_RUNNER_PATH}/dist/templates/global-setup`),
globalTeardown: require.resolve(`${TEST_RUNNER_PATH}/dist/templates/global-teardown`),
testEnvironment: require.resolve(`${TEST_RUNNER_PATH}/dist/templates/custom-environment`),
setupFilesAfterEnv: [
require.resolve(TEST_RUNNER_PATH + '/dist/templates/jest-setup'),
require.resolve(`${TEST_RUNNER_PATH}/dist/templates/jest-setup`),
expectPlaywrightPath,
path.join(presetBasePath, 'lib', 'extends.js'),
],
Expand Down Expand Up @@ -70,9 +71,9 @@ export const getJestConfig = (): Config.InitialOptions => {

const reporters = STORYBOOK_JUNIT ? ['default', jestJunitPath] : ['default'];

const testMatch = (STORYBOOK_STORIES_PATTERN && STORYBOOK_STORIES_PATTERN.split(';')) || [];
const testMatch = STORYBOOK_STORIES_PATTERN?.split(';') ?? [];

let config: Config.InitialOptions = {
const config: Config.InitialOptions = {
rootDir: getProjectRoot(),
roots: TEST_ROOT ? [TEST_ROOT] : undefined,
reporters,
Expand Down
17 changes: 4 additions & 13 deletions src/playwright/transformPlaywrightJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
describe('Playwright Json', () => {
describe('v4 indexes', () => {
it('should generate a test for each story', () => {
const input: V4Index = {
const input = {
v: 4,
entries: {
'example-header--logged-in': {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('Playwright Json', () => {
});

it('should skip docs entries', () => {
const input: V4Index = {
const input = {
v: 4,
entries: {
'example-introduction--page': {
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('Playwright Json', () => {

describe('v3 indexes', () => {
it('should generate a test for each story', () => {
const input: V3StoriesIndex = {
const input = {
v: 3,
stories: {
'example-header--logged-in': {
Expand Down Expand Up @@ -490,7 +490,7 @@ describe('Playwright Json', () => {
});

it('should skip docs-only stories', () => {
const input: V3StoriesIndex = {
const input = {
v: 3,
stories: {
'example-introduction--page': {
Expand Down Expand Up @@ -577,15 +577,6 @@ describe('Playwright Json', () => {
`);
});
});

describe('unsupported index', () => {
it('throws an error for unsupported versions', () => {
const unsupportedVersion: UnsupportedVersion = { v: 1 };
expect(() => transformPlaywrightJson(unsupportedVersion)).toThrowError(
`Unsupported version ${unsupportedVersion.v}`
);
});
});
});

describe('unsupported index', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type TestHook } from './playwright/hooks';
import { TestHook } from './playwright/hooks';
import { type setupPage } from './setup-page';
import type { StoryContext, StoryIdentifiers } from '@storybook/csf';

declare global {
var __sbPreRender: TestHook;
var __sbPostRender: TestHook;
Expand Down

0 comments on commit a6179ff

Please sign in to comment.