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

Addon-storyshots: Upgrade to jest 26 #10642

Merged
merged 1 commit into from
May 7, 2020
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
2 changes: 1 addition & 1 deletion addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.9.6",
"@egoist/vue-to-react": "^1.1.0",
"@jest/transform": "^25.2.4",
"@jest/transform": "^26.0.0",
"@mdx-js/loader": "^1.5.1",
"@mdx-js/mdx": "^1.5.1",
"@mdx-js/react": "^1.5.1",
Expand Down
2 changes: 1 addition & 1 deletion addons/storyshots/storyshots-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"storybook": "start-storybook -p 6006"
},
"dependencies": {
"@jest/transform": "^25.2.4",
"@jest/transform": "^26.0.0",
"@storybook/addons": "6.0.0-beta.2",
"@storybook/client-api": "6.0.0-beta.2",
"@storybook/core": "6.0.0-beta.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { StoryshotsOptions } from '../../api/StoryshotsOptions';

function setupAngularJestPreset() {
// Needed to prevent "Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten."
require.requireActual('core-js');
require.requireActual('core-js/modules/es.promise');
// require.requireActual('core-js/es6/reflect');
// require.requireActual('core-js/es7/reflect');
jest.requireActual('core-js');
jest.requireActual('core-js/modules/es.promise');
// jest.requireActual('core-js/es6/reflect');
// jest.requireActual('core-js/es7/reflect');

// Angular + Jest + Storyshots = Crazy Shit:
// We need to require 'jest-preset-angular/setupJest' before any storybook code
// is running inside jest - one of the things that `jest-preset-angular/setupJest` does is
// extending the `window.Reflect` with all the needed metadata functions, that are required
// for emission of the TS decorations like 'design:paramtypes'
require.requireActual('jest-preset-angular/setupJest');
jest.requireActual('jest-preset-angular/setupJest');
}

function test(options: StoryshotsOptions): boolean {
Expand All @@ -29,13 +29,13 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
setupAngularJestPreset();

const storybook = require.requireActual('@storybook/angular');
const storybook = jest.requireActual('@storybook/angular');

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

return {
framework: 'angular' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for angular');
},
Expand Down
4 changes: 2 additions & 2 deletions addons/storyshots/storyshots-core/src/frameworks/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getConfigPathParts(input: string): Output {
output.files.push(preview);
}
if (main) {
const { stories = [] } = require.requireActual(main);
const { stories = [] } = jest.requireActual(main);

output.stories = stories.map(
(pattern: string | { path: string; recursive: boolean; match: string }) => {
Expand Down Expand Up @@ -80,7 +80,7 @@ function configure(
const { files, stories } = getConfigPathParts(configPath);

files.forEach((f) => {
require.requireActual(f);
jest.requireActual(f);
});

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

const storybook = require.requireActual('@storybook/html');
const storybook = jest.requireActual('@storybook/html');

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

return {
framework: 'html' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for HTML');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'preact';

const storybook = require.requireActual('@storybook/preact');
const storybook = jest.requireActual('@storybook/preact');

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

return {
framework: 'preact' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for preact');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'rax';

const storybook = require.requireActual('@storybook/rax');
const storybook = jest.requireActual('@storybook/rax');

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

return {
framework: 'rax' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for rax');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ function configure(options: StoryshotsOptions, storybook: any) {
}

const resolvedConfigPath = path.resolve(configPath);
require.requireActual(resolvedConfigPath);
jest.requireActual(resolvedConfigPath);
}

function load(options: StoryshotsOptions) {
const storybook = require.requireActual('@storybook/react-native');
const storybook = jest.requireActual('@storybook/react-native');

configure(options, storybook);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ function test(options: StoryshotsOptions): boolean {
}

function load(options: StoryshotsOptions) {
const storybook = require.requireActual('@storybook/react');
const storybook = jest.requireActual('@storybook/react');

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

return {
framework: 'react' as const,
renderTree: require.requireActual('./renderTree').default,
renderShallowTree: require.requireActual('./renderShallowTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: jest.requireActual('./renderShallowTree').default,
storybook,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Loader } from '../Loader';
import { StoryshotsOptions } from '../../api/StoryshotsOptions';

function mockRiotToIncludeCompiler() {
jest.mock('riot', () => require.requireActual('riot/riot.js'));
jest.mock('riot', () => jest.requireActual('riot/riot.js'));
}

function test(options: StoryshotsOptions): boolean {
Expand All @@ -16,13 +16,13 @@ function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'riot';
mockRiotToIncludeCompiler();

const storybook = require.requireActual('@storybook/riot');
const storybook = jest.requireActual('@storybook/riot');

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

return {
framework: 'riot' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for riot');
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { document } from 'global';

const riotForStorybook = require.requireActual('@storybook/riot');
const riotForStorybook = jest.requireActual('@storybook/riot');

function bootstrapADocumentAndReturnANode() {
const rootElement = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function test(options: StoryshotsOptions): boolean {
function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'svelte';

const storybook = require.requireActual('@storybook/svelte');
const storybook = jest.requireActual('@storybook/svelte');

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

return {
framework: 'svelte' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for svelte');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Loader } from '../Loader';
import { StoryshotsOptions } from '../../api/StoryshotsOptions';

function mockVueToIncludeCompiler() {
jest.mock('vue', () => require.requireActual('vue/dist/vue.common.js'));
jest.mock('vue', () => jest.requireActual('vue/dist/vue.common.js'));
}

function test(options: StoryshotsOptions): boolean {
Expand All @@ -16,13 +16,13 @@ function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'vue';
mockVueToIncludeCompiler();

const storybook = require.requireActual('@storybook/vue');
const storybook = jest.requireActual('@storybook/vue');

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

return {
framework: 'vue' as const,
renderTree: require.requireActual('./renderTree').default,
renderTree: jest.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for vue');
},
Expand Down
26 changes: 13 additions & 13 deletions lib/core/src/server/presets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jest.mock('./utils/resolve-file', () => ({

describe('presets', () => {
it('does not throw when there is no preset file', async () => {
const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
let presets;

async function testPresets() {
Expand All @@ -48,7 +48,7 @@ describe('presets', () => {
});

it('does not throw when presets are empty', async () => {
const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(getPresets([]));

async function testPresets() {
Expand All @@ -60,7 +60,7 @@ describe('presets', () => {
});

it('does not throw when preset can not be loaded', async () => {
const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(getPresets(['preset-foo']));

async function testPresets() {
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('presets', () => {
foo: (exec, options) => exec.concat(`valar ${options.custom}`),
});

const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = getPresets(['preset-foo', 'preset-got', 'preset-bar']);

const result = await presets.apply('foo', []);
Expand All @@ -113,7 +113,7 @@ describe('presets', () => {
babel: mockPresetBarExtendBabel,
});

const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(getPresets(['preset-foo', 'preset-bar']));

async function testPresets() {
Expand All @@ -139,7 +139,7 @@ describe('presets', () => {
babel: mockPresetBarExtendBabel,
});

const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(getPresets([{ name: 'preset-foo' }, { name: 'preset-bar' }]));

async function testPresets() {
Expand All @@ -165,7 +165,7 @@ describe('presets', () => {
babel: mockPresetBarExtendBabel,
});

const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(
getPresets([
{ name: 'preset-foo', options: { foo: 1 } },
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('presets', () => {
babel: mockPresetBarExtendBabel,
});

const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(
getPresets([
'preset-foo',
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('presets', () => {
webpack: mockPresetBarExtendWebpack,
});

const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const presets = wrapPreset(
getPresets([
'preset-foo',
Expand Down Expand Up @@ -279,7 +279,7 @@ describe('presets', () => {
});

it('allows for presets to export presets array', async () => {
const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const input = {};
const mockPresetBar = jest.fn(() => input);

Expand All @@ -301,7 +301,7 @@ describe('presets', () => {
});

it('allows for presets to export presets fn', async () => {
const getPresets = require.requireActual('./presets').default;
const getPresets = jest.requireActual('./presets').default;
const input = {};
const storybookOptions = { a: 1 };
const presetOptions = { b: 2 };
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('presets', () => {
});

describe('resolveAddonName', () => {
const { resolveAddonName } = require.requireActual('./presets');
const { resolveAddonName } = jest.requireActual('./presets');

it('should resolve packages with metadata (relative path)', () => {
expect(resolveAddonName('@storybook/addon-docs')).toEqual({
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('resolveAddonName', () => {
});

describe('splitAddons', () => {
const { splitAddons } = require.requireActual('./presets');
const { splitAddons } = jest.requireActual('./presets');

it('should split managerEntries that end in register', () => {
const addons = [
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@
"husky": "^4.0.10",
"inquirer": "^7.0.0",
"jest": "^25.5.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed one 😀

"jest-cli": "^25.5.2",
"jest-config": "^25.5.2",
"jest-diff": "^25.5.0",
"jest-cli": "^26.0.0",
"jest-config": "^26.0.0",
"jest-diff": "^26.0.0",
"jest-emotion": "^10.0.17",
"jest-environment-jsdom": "^25.5.0",
"jest-environment-jsdom": "^26.0.0",
"jest-environment-jsdom-thirteen": "^1.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably don't need this one, we ship with 16 now

"jest-enzyme": "^7.0.2",
"jest-image-snapshot": "^3.1.0",
"jest-jasmine2": "^25.5.2",
"jest-matcher-utils": "^25.5.0",
"jest-jasmine2": "^26.0.0",
"jest-matcher-utils": "^26.0.0",
"jest-preset-angular": "^6.0.1",
"jest-raw-loader": "^1.0.1",
"jest-serializer-html": "^7.0.0",
Expand Down
Loading