Skip to content

Commit

Permalink
Merge pull request #512 from storybookjs/yann/update-test-runner-cpc
Browse files Browse the repository at this point in the history
Align with Storybook 8.2 core package layout
  • Loading branch information
yannbf authored Nov 4, 2024
2 parents b7ee85b + 96a0fc6 commit 69677a3
Show file tree
Hide file tree
Showing 17 changed files with 4,959 additions and 8,143 deletions.
874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.3.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.1.cjs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
enableTelemetry: 0
compressionLevel: mixed

enableGlobalCache: false

enableTelemetry: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.6.3.cjs
yarnPath: .yarn/releases/yarn-4.5.1.cjs
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ Use the following table to use the correct version of this package, based on the

| Test runner version | Storybook version |
| ------------------- | ----------------- |
| ^0.17.0 | ^8.0.0 |
| ^0.19.0 | ^8.2.0 |
| ~0.17.0 | ^8.0.0 |
| ~0.16.0 | ^7.0.0 |
| ~0.9.4 | ^6.4.0 |

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
"@babel/template": "^7.22.5",
"@babel/types": "^7.22.5",
"@jest/types": "^29.6.3",
"@storybook/core-common": "next",
"@storybook/csf": "^0.1.11",
"@storybook/csf-tools": "next",
"@storybook/preview-api": "next",
"@swc/core": "^1.5.22",
"@swc/jest": "^0.2.23",
"expect-playwright": "^0.8.0",
Expand Down Expand Up @@ -116,6 +113,9 @@
"vite": "^4.4.5",
"wait-on": "^7.2.0"
},
"peerDependencies": {
"storybook": "^8.2.0 || ^8.3.0-0 || ^8.4.0-0 || ^8.5.0-0 || ^8.6.0-0"
},
"engines": {
"node": "^16.10.0 || ^18.0.0 || >=20.0.0"
},
Expand All @@ -139,5 +139,6 @@
"react-native"
],
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
}
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion src/config/jest-playwright.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { getProjectRoot } from '@storybook/core-common';
import { getProjectRoot } from 'storybook/internal/common';
import type { Config } from '@jest/types';

const getTestRunnerPath = () => process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/test-runner';
Expand Down
5 changes: 3 additions & 2 deletions src/csf/transformCsf.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-underscore-dangle */
import { loadCsf } from '@storybook/csf-tools';
import { toId, storyNameFromExport, combineTags } from '@storybook/csf';
import { loadCsf } from 'storybook/internal/csf-tools';
import * as t from '@babel/types';
import generate from '@babel/generator';
import { toId, storyNameFromExport, combineTags } from '@storybook/csf';
import dedent from 'ts-dedent';

import { getTagOptions } from '../util/getTagOptions';
Expand Down Expand Up @@ -124,6 +124,7 @@ export const transformCsf = (
const annotations = csf._storyAnnotations[key];
acc[key] = {};
if (annotations?.play) {
// @ts-expect-error type mismatch – check later
acc[key].play = annotations.play;
}

Expand Down
4 changes: 2 additions & 2 deletions src/playwright/transformPlaywright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as storybookMain from '../util/getStorybookMain';

import { transformPlaywright } from './transformPlaywright';

jest.mock('@storybook/core-common', () => ({
...jest.requireActual('@storybook/core-common'),
jest.mock('storybook/internal/common', () => ({
...jest.requireActual('storybook/internal/common'),
getProjectRoot: jest.fn(() => '/foo/bar'),
normalizeStories: jest.fn(() => [
{
Expand Down
4 changes: 2 additions & 2 deletions src/playwright/transformPlaywright.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { relative } from 'path';
import template from '@babel/template';
import { userOrAutoTitle } from '@storybook/preview-api';
import { userOrAutoTitle } from 'storybook/internal/preview-api';
import dedent from 'ts-dedent';

import { getStorybookMetadata } from '../util';
import { transformCsf } from '../csf/transformCsf';
import type { TestPrefixer } from '../csf/transformCsf';
import dedent from 'ts-dedent';

const coverageErrorMessage = dedent`
[Test runner] An error occurred when evaluating code coverage:
Expand Down
7 changes: 3 additions & 4 deletions src/test-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import canBindToHost from 'can-bind-to-host';
import dedent from 'ts-dedent';
import path, { join, resolve } from 'path';
import tempy from 'tempy';
import { getInterpretedFile } from 'storybook/internal/common';
import { readConfig } from 'storybook/internal/csf-tools';
import { glob } from 'glob';

import { JestOptions, getCliOptions } from './util/getCliOptions';
import { getStorybookMetadata } from './util/getStorybookMetadata';
import { getTestRunnerConfig } from './util/getTestRunnerConfig';
import { transformPlaywrightJson } from './playwright/transformPlaywrightJson';

import { glob } from 'glob';
import { TestRunnerConfig } from './playwright/hooks';
import { getInterpretedFile } from '@storybook/core-common';
import { readConfig } from '@storybook/csf-tools';

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
Expand Down
4 changes: 2 additions & 2 deletions src/util/getStorybookMain.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getStorybookMain, resetStorybookMainCache, storybookMainConfig } from './getStorybookMain';
import * as coreCommon from '@storybook/core-common';
import * as coreCommon from 'storybook/internal/common';

jest.mock('@storybook/core-common');
jest.mock('storybook/internal/common');

describe('getStorybookMain', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/util/getStorybookMain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join, resolve } from 'path';
import { serverRequire } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/types';
import { serverRequire } from 'storybook/internal/common';
import type { StorybookConfig } from 'storybook/internal/types';
import dedent from 'ts-dedent';

export const storybookMainConfig = new Map<string, StorybookConfig>();
Expand Down
8 changes: 4 additions & 4 deletions src/util/getStorybookMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StorybookConfig } from '@storybook/types';
import * as storybookMain from './getStorybookMain';
import { StorybookConfig } from 'storybook/internal/types';

import * as storybookMain from './getStorybookMain';
import { getStorybookMetadata } from './getStorybookMetadata';

jest.mock('@storybook/core-common', () => ({
...jest.requireActual('@storybook/core-common'),
jest.mock('storybook/internal/common', () => ({
...jest.requireActual('storybook/internal/common'),
getProjectRoot: jest.fn(() => '/foo/bar'),
normalizeStories: jest.fn(() => [
{
Expand Down
7 changes: 4 additions & 3 deletions src/util/getStorybookMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { join } from 'path';
import { normalizeStories, getProjectRoot } from '@storybook/core-common';
import { normalizeStories, getProjectRoot } from 'storybook/internal/common';
import { StoriesEntry } from 'storybook/internal/types';

import { getStorybookMain } from './getStorybookMain';
import { StoriesEntry } from '@storybook/types';

export const getStorybookMetadata = () => {
const workingDir = getProjectRoot();
Expand All @@ -21,7 +22,7 @@ export const getStorybookMetadata = () => {
.map((dir) => join(workingDir, dir))
.join(';');

// @ts-ignore -- this is added in @storybook/core-[email protected], which we don't depend on
// @ts-expect-error -- this is added in storybook/internal/[email protected], which we don't depend on
const lazyCompilation = !!main.core?.builder?.options?.lazyCompilation;

return {
Expand Down
8 changes: 4 additions & 4 deletions src/util/getTestRunnerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const testRunnerConfig: TestRunnerConfig = {
},
};

jest.mock('@storybook/core-common', () => ({
jest.mock('storybook/internal/common', () => ({
serverRequire: jest.fn(),
}));

Expand All @@ -37,21 +37,21 @@ describe('getTestRunnerConfig', () => {

it('should load the test runner config', () => {
const configDir = '.storybook';
(require('@storybook/core-common').serverRequire as jest.Mock).mockReturnValueOnce(
(require('storybook/internal/common').serverRequire as jest.Mock).mockReturnValueOnce(
testRunnerConfig
);

const result = getTestRunnerConfig(configDir);

expect(result).toEqual(testRunnerConfig);
expect(require('@storybook/core-common').serverRequire).toHaveBeenCalledWith(
expect(require('storybook/internal/common').serverRequire).toHaveBeenCalledWith(
join(resolve('.storybook', 'test-runner'))
);
});

it('should cache the test runner config', () => {
const configDir = '.storybook';
(require('@storybook/core-common').serverRequire as jest.Mock).mockReturnValueOnce(
(require('storybook/internal/common').serverRequire as jest.Mock).mockReturnValueOnce(
testRunnerConfig
);

Expand Down
2 changes: 1 addition & 1 deletion src/util/getTestRunnerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, resolve } from 'path';
import { serverRequire } from '@storybook/core-common';
import { serverRequire } from 'storybook/internal/common';
import { TestRunnerConfig } from '../playwright/hooks';

let testRunnerConfig: TestRunnerConfig;
Expand Down
Loading

0 comments on commit 69677a3

Please sign in to comment.