Skip to content

Commit

Permalink
Merge pull request #25584 from storybookjs/valentin/replace-storybook…
Browse files Browse the repository at this point in the history
…-jest-by-test

Interaction: Replace @storybook/jest by @storybook/test
  • Loading branch information
valentinpalkovic authored Jan 15, 2024
2 parents 52931d1 + 7813402 commit 8cc1d71
Show file tree
Hide file tree
Showing 60 changed files with 123 additions and 336 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { global as globalThis } from '@storybook/global';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { within } from '@storybook/testing-library';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"@storybook/core-common": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/instrumenter": "workspace:*",
"@storybook/jest": "next",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/testing-library": "next",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StoryObj, Meta } from '@storybook/react';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { CallStates } from '@storybook/instrumenter';
import { userEvent, within } from '@storybook/testing-library';
import { getCalls } from '../mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { StoryObj, Meta } from '@storybook/react';
import { CallStates } from '@storybook/instrumenter';
import { styled } from '@storybook/theming';
import { userEvent, within, waitFor } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import isChromatic from 'chromatic/isChromatic';

import { getCalls, getInteractions } from '../mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { vi, describe, beforeEach, expect } from 'vitest';
import { vi, describe, beforeEach, expect, it, afterEach } from 'vitest';
import { Architect, createBuilder } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { schema } from '@angular-devkit/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { vi, describe, expect, it, beforeEach } from 'vitest';
import { vi, describe, expect, it, beforeEach, afterEach } from 'vitest';
import { Architect, createBuilder } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { schema } from '@angular-devkit/core';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { ArgTypes } from '@storybook/types';
import { describe, it, expect } from 'vitest';
import { computesTemplateSourceFromComponent } from './ComputesTemplateFromComponent';
import { ISomeInterface, ButtonAccent, InputComponent } from './__testfixtures__/input.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
import { Component, ɵresetJitOptions } from '@angular/core';
import { platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
Expand All @@ -14,7 +14,6 @@ describe('RendererFactory', () => {
let rendererFactory: RendererFactory;
let rootTargetDOMNode: HTMLElement;
let rootDocstargetDOMNode: HTMLElement;
let storyInDocstargetDOMNode: HTMLElement;

beforeEach(async () => {
rendererFactory = new RendererFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NgModule, Type, Component, EventEmitter, Input, Output } from '@angular/core';
import { NgModule, Component, EventEmitter, Input, Output } from '@angular/core';
import { describe, expect, it } from 'vitest';

import { TestBed } from '@angular/core/testing';
import { BehaviorSubject } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { describe, expect, it } from 'vitest';

import {
getComponentInputsOutputs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, NgModule } from '@angular/core';
import { describe, expect, it } from 'vitest';
import { isComponentAlreadyDeclared } from './NgModulesAnalyzer';

const FooComponent = Component({})(class {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
provideNoopAnimations,
} from '@angular/platform-browser/animations';
import { NgModuleMetadata } from '../../types';
import { PropertyExtractor, REMOVED_MODULES } from './PropertyExtractor';
import { PropertyExtractor } from './PropertyExtractor';
import { WithOfficialModule } from '../__testfixtures__/test.module';

const TEST_TOKEN = new InjectionToken('testToken');
Expand All @@ -18,7 +18,6 @@ const TestService = Injectable()(class {});
const TestComponent1 = Component({})(class {});
const TestComponent2 = Component({})(class {});
const StandaloneTestComponent = Component({ standalone: true })(class {});
const TestDirective = Directive({})(class {});
const StandaloneTestDirective = Directive({ standalone: true })(class {});
const TestModuleWithDeclarations = NgModule({ declarations: [TestComponent1] })(class {});
const TestModuleWithImportsAndProviders = NgModule({
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/angular/src/client/argsToTemplate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest';
import { argsToTemplate, ArgsToTemplateOptions } from './argsToTemplate'; // adjust path

describe('argsToTemplate', () => {
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/angular/src/client/decorateStory.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Input, Output } from '@angular/core';
import { DecoratorFunction, StoryContext } from '@storybook/types';
import { describe, expect, it } from 'vitest';
import { componentWrapperDecorator } from './decorators';

import decorateStory from './decorateStory';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
import path from 'path';
import fs from 'fs';
import tmp from 'tmp';
import { sync as spawnSync } from 'cross-spawn';

import { findComponentByName, extractArgTypesFromData } from './compodoc';

// @ts-expect-error (Converted from ts-ignore)
const { SNAPSHOT_OS } = global;
import { describe, expect, it } from 'vitest';

// File hierarchy: __testfixtures__ / some-test-case / input.*
const inputRegExp = /^input\..*$/;

const runCompodoc = (inputPath: string) => {
const testDir = path.dirname(inputPath);
const { name: tmpDir, removeCallback } = tmp.dirSync();

// FIXME: for now, this requires a tsconfig.json for each test case. Tried generating
// one dynamically in tmpDir, but compodoc doesn't handle absolute paths properly
// (and screwed around with relative paths as well, but couldn't get it working)
spawnSync('yarn', ['compodoc', '-p', `${testDir}/tsconfig.json`, '-e', 'json', '-d', tmpDir], {
stdio: 'inherit',
shell: true,
});
const output = fs.readFileSync(`${tmpDir}/documentation.json`, 'utf8');
try {
removeCallback();
} catch (e) {
//
}
return output;
};

describe('angular component properties', () => {
const fixturesDir = path.join(__dirname, '__testfixtures__');
fs.readdirSync(fixturesDir, { withFileTypes: true }).forEach((testEntry) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryObj, applicationConfig } from '@storybook/angular';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { within, userEvent } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { importProvidersFrom } from '@angular/core';
import { OpenCloseComponent } from '../moduleMetadata/angular-src/open-close-component/open-close.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryObj } from '@storybook/angular';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { within, userEvent } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { importProvidersFrom } from '@angular/core';
import { OpenCloseComponent } from '../moduleMetadata/angular-src/open-close-component/open-close.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-undef */
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import Head from 'next/head';
import React from 'react';
import { within, userEvent, waitFor } from '@storybook/testing-library';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type StoriesEntry } from '@storybook/types';
import { normalizeStoriesEntry } from '@storybook/core-common';
import { join } from 'path';
import slash from 'slash';
import { vi, it, describe } from 'vitest';
import { vi, it, describe, expect } from 'vitest';
import { removeMDXEntries } from '../remove-mdx-entries';

const configDir = '/configDir/';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

const arrows = {
ArrowUp: { name: 'ArrowUp' },
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/argTypes.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/args.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import pick from 'lodash/pick';
import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, RESET_STORY_ARGS } from '@storybook/core-events';

Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/autotitle.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { global as globalThis } from '@storybook/global';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { PlayFunctionContext } from '@storybook/types';

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
StoryContext,
} from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { useEffect } from '@storybook/preview-api';
import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, RESET_STORY_ARGS } from '@storybook/core-events';

Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/globals.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/indexer.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { global as globalThis } from '@storybook/global';
import type { PlayFunctionContext } from '@storybook/types';

Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/loaders.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/names.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { global as globalThis } from '@storybook/global';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { PlayFunctionContext } from '@storybook/types';

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/rendering.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PlayFunctionContext } from '@storybook/types';
import { within, waitFor } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import {
FORCE_REMOUNT,
RESET_STORY_ARGS,
Expand Down
4 changes: 2 additions & 2 deletions code/lib/preview-api/template/stories/shortcuts.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import { userEvent, within } from '@storybook/testing-library';
import { PREVIEW_KEYDOWN } from '@storybook/core-events';
import { jest, expect } from '@storybook/jest';
import { expect, fn } from '@storybook/test';
import type { PlayFunctionContext } from '@storybook/csf';

export default {
Expand All @@ -13,7 +13,7 @@ export const KeydownDuringPlay = {
play: async ({ canvasElement }: PlayFunctionContext<any>) => {
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;

const previewKeydown = jest.fn();
const previewKeydown = fn();
channel.on(PREVIEW_KEYDOWN, previewKeydown);
const button = await within(canvasElement).findByText('Submit');
await userEvent.type(button, 's');
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/tags.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types';
import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/title.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { global as globalThis } from '@storybook/global';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { PlayFunctionContext } from '@storybook/types';

export default {
Expand Down
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
"@storybook/html-vite": "workspace:*",
"@storybook/html-webpack5": "workspace:*",
"@storybook/instrumenter": "workspace:*",
"@storybook/jest": "next",
"@storybook/linter-config": "^3.1.2",
"@storybook/manager": "workspace:*",
"@storybook/manager-api": "workspace:*",
Expand Down Expand Up @@ -162,6 +161,7 @@
"@storybook/svelte": "workspace:*",
"@storybook/svelte-webpack5": "workspace:*",
"@storybook/telemetry": "workspace:*",
"@storybook/test": "next",
"@storybook/testing-library": "next",
"@storybook/theming": "workspace:*",
"@storybook/types": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/svelte/template/stories/args.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { within, userEvent, waitFor } from '@storybook/testing-library';
import {
UPDATE_STORY_ARGS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { Meta, StoryObj } from '@storybook/vue3';
import { within } from '@storybook/testing-library';
import { inject } from 'vue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { global as globalThis } from '@storybook/global';
import type { Meta, StoryObj, StoryFn } from '@storybook/vue3';
import { within, userEvent } from '@storybook/testing-library';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { global as globalThis } from '@storybook/global';
import { within } from '@storybook/testing-library';
import { STORY_ARGS_UPDATED, RESET_STORY_ARGS, UPDATE_STORY_ARGS } from '@storybook/core-events';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { global as globalThis } from '@storybook/global';
import type { Channel } from '@storybook/channels';
import { within } from '@storybook/testing-library';
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/src/controls/Boolean.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { Meta, StoryObj } from '@storybook/react';
import { within, fireEvent, waitFor } from '@storybook/testing-library';
import { addons } from '@storybook/preview-api';
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/src/examples/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { Meta, StoryObj } from '@storybook/react';
import { within, fireEvent } from '@storybook/testing-library';
import React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion code/ui/components/src/components/tabs/tabs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import React, { Fragment } from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta, StoryObj } from '@storybook/react';
Expand Down
2 changes: 1 addition & 1 deletion code/ui/manager/src/components/sidebar/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ComponentProps } from 'react';
import React from 'react';
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import type { Meta, StoryObj } from '@storybook/react';

import { TooltipLinkList } from '@storybook/components';
Expand Down
Loading

0 comments on commit 8cc1d71

Please sign in to comment.