diff --git a/LICENSE b/LICENSE index 62eb6dad..fef93981 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Storybook contributors +Copyright (c) 2022 Storybook contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/jsdom-jest.config.js b/jsdom-jest.config.js deleted file mode 100644 index 6dbbf297..00000000 --- a/jsdom-jest.config.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - cacheDirectory: '.cache/jest', - testMatch: ['**/*.stories.[jt]s?(x)'], - moduleNameMapper: { - // non-js files - '\\.(jpg|jpeg|png|apng|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/mocks/fileMock.js', - '\\.(css|scss|stylesheet)$': '/mocks/styleMock.js', - }, - transform: { - '^.+\\.stories\\.[jt]sx?$': './jsdom/transform', - '^.+\\.[jt]sx?$': 'babel-jest', - }, - testEnvironment: 'jest-environment-jsdom', -}; diff --git a/jsdom/transform.js b/jsdom/transform.js deleted file mode 100644 index 5f94fd02..00000000 --- a/jsdom/transform.js +++ /dev/null @@ -1,20 +0,0 @@ -const { transform: babelTransform } = require('@babel/core'); -const { transformJsdom } = require('../dist/cjs/jsdom/transformJsdom'); - -module.exports = { - process(src, filename, config) { - const csfTest = transformJsdom(src); - - const result = babelTransform(csfTest, { - filename, - babelrc: false, - configFile: false, - presets: [ - ['@babel/preset-env', { targets: { node: 'current' } }], - '@babel/preset-typescript', - '@babel/preset-react', - ], - }); - return result ? result.code : src; - }, -}; diff --git a/mocks/fileMock.js b/mocks/fileMock.js deleted file mode 100644 index 105ff497..00000000 --- a/mocks/fileMock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'file-stub'; diff --git a/mocks/htmlMock.js b/mocks/htmlMock.js deleted file mode 100644 index 0062fcfe..00000000 --- a/mocks/htmlMock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = '

HTML Mock

'; diff --git a/mocks/styleMock.js b/mocks/styleMock.js deleted file mode 100644 index f053ebf7..00000000 --- a/mocks/styleMock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {}; diff --git a/package.json b/package.json index 4f192228..0f085414 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,6 @@ "dist/**/*", "README.md", "playwright", - "jsdom", - "mocks", "*.js", "*.d.ts" ], @@ -43,13 +41,11 @@ "start": "concurrently \"yarn build:watch\" \"yarn storybook -- --no-manager-cache --quiet\"", "build-storybook": "build-storybook", "release": "yarn build && auto shipit", - "test-storybook": "node bin/test-storybook.js --no-cache", + "test-storybook": "node bin/test-storybook.js", + "test-storybook:no-cache": "yarn test-storybook --no-cache", + "test-storybook:json": "yarn test-storybook --stories-json", "test-storybook:ci": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn build-storybook --quiet && npx http-server storybook-static --port 6006 --silent\" \"wait-on tcp:6006 && yarn test-storybook\"", - "test-storybook:ci-json": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn build-storybook --quiet && npx http-server storybook-static --port 6006 --silent\" \"wait-on tcp:6006 && yarn test-storybook --stories-json\"", - "test-storybook:jsdom": "jest --no-cache --config ./jsdom-jest.config.js -i", - "test-storybook:playwright-no-cache": "jest --no-cache --config ./test-runner-jest.config.js", - "test-storybook:playwright": "./bin/test-storybook.js", - "test-storybook:playwright-json": "./bin/test-storybook.js --stories-json", + "test-storybook:ci-json": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn build-storybook --quiet && npx http-server storybook-static --port 6006 --silent\" \"wait-on tcp:6006 && yarn test-storybook:json\"", "generate-dynamic-stories": "node scripts/generate-dynamic-stories.js" }, "bin": { diff --git a/preset.js b/preset.js deleted file mode 100644 index 37cc891e..00000000 --- a/preset.js +++ /dev/null @@ -1,12 +0,0 @@ -function config(entry = []) { - return [...entry, require.resolve("./dist/esm/preset/preview")]; -} - -function managerEntries(entry = []) { - return [...entry, require.resolve("./dist/esm/preset/manager")]; -} - -module.exports = { - managerEntries, - config, -}; diff --git a/src/jsdom/index.ts b/src/jsdom/index.ts deleted file mode 100644 index 66d198f4..00000000 --- a/src/jsdom/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { transform as babelTransform } from '@babel/core'; -import { transformJsdom } from './transformJsdom'; - -export const process = (src: string, filename: string, config: any) => { - const csfTest = transformJsdom(src); - - const result = babelTransform(csfTest, { - filename, - babelrc: false, - configFile: false, - presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'], - }); - return result ? result.code : src; -}; diff --git a/src/jsdom/transformJsdom.test.ts b/src/jsdom/transformJsdom.test.ts deleted file mode 100644 index 49dac20f..00000000 --- a/src/jsdom/transformJsdom.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import dedent from 'ts-dedent'; -import { transformJsdom } from './transformJsdom'; - -// @ts-ignore -expect.addSnapshotSerializer({ - print: (val: any) => val, - test: (val: any) => true, -}); - -describe('transformJsdom', () => { - it('basic', () => { - expect( - transformJsdom(dedent` - export default { title: 'foo/bar' }; - export const A = () => {}; - `) - ).toMatchInlineSnapshot(` - import { render, screen } from "@testing-library/react"; - import { composeStory } from "@storybook/testing-react"; - export default { title: 'foo/bar' }; - export const A = () => {}; - - if (!require.main) { - describe("foo/bar", () => { - describe("A", () => { - it("smoke-test", async () => { - const Composed = await composeStory(A, exports.default); - const { - container - } = render(); - - if (Composed.play) { - await Composed.play({ - canvasElement: container - }); - } - }); - }); - }); - } - `); - }); -}); diff --git a/src/jsdom/transformJsdom.ts b/src/jsdom/transformJsdom.ts deleted file mode 100644 index b12c5dea..00000000 --- a/src/jsdom/transformJsdom.ts +++ /dev/null @@ -1,29 +0,0 @@ -import template from '@babel/template'; -import { transformCsf } from '../csf/transformCsf'; - -const filePrefixer = template(` - import { render, screen } from "@testing-library/react"; - import { composeStory } from "@storybook/testing-react"; -`); - -const testPrefixer = template( - ` - console.log({ id: %%id%%, title: %%title%%, name: %%name%%, storyExport: %%storyExport%% }); - async () => { - const Composed = await composeStory(%%storyExport%%, exports.default); - const { container } = render(); - if(Composed.play) { - await Composed.play({ canvasElement: container }); - } - } - `, - { - plugins: ['jsx'], - } -); - -export const transformJsdom = (src: string) => { - // @ts-ignore - const result = transformCsf(src, { filePrefixer, testPrefixer, insertTestIfEmpty: true }); - return result; -};