-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Presets } from 'storybook/internal/types' | ||
import { describe, expect } from 'vitest' | ||
import type { RsbuildBuilderOptions } from '../src/preview/iframe-rsbuild.config' | ||
|
||
// @ts-expect-error TODO | ||
const dummyOptions: RsbuildBuilderOptions = { | ||
configType: 'DEVELOPMENT', | ||
configDir: '', | ||
packageJson: {}, | ||
presets: { | ||
apply: async (key: string) => | ||
({ | ||
framework: { | ||
name: '', | ||
}, | ||
addons: [], | ||
core: { | ||
builder: {}, | ||
}, | ||
options: {}, | ||
})[key], | ||
} as Presets, | ||
presetsList: [], | ||
typescriptOptions: { | ||
check: false, | ||
skipCompiler: true, | ||
}, | ||
} | ||
|
||
describe('dummy', () => { | ||
expect(1).toBe(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/**/*"] | ||
"include": ["src/**/*", "tests/**/*"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Code taken from https://github.com/storybookjs/storybook/blob/next/code/vitest-setup.ts. | ||
import '@testing-library/jest-dom/vitest' | ||
import { expect, vi } from 'vitest' | ||
|
||
import { dedent } from 'ts-dedent' | ||
|
||
const ignoreList = [ | ||
(error: any) => error.message.includes('":nth-child" is potentially unsafe'), | ||
(error: any) => | ||
error.message.includes('":first-child" is potentially unsafe'), | ||
(error: any) => | ||
error.message.match(/Browserslist: .* is outdated. Please run:/), | ||
(error: any) => | ||
error.message.includes('react-async-component-lifecycle-hooks') && | ||
error.stack.includes('addons/knobs/src/components/__tests__/Options.js'), | ||
// React will log this error even if you catch an error with a boundary. I guess it's to | ||
// help in development. See https://github.com/facebook/react/issues/15069 | ||
(error: any) => | ||
error.message.match( | ||
/React will try to recreate this component tree from scratch using the error boundary you provided/, | ||
), | ||
(error: any) => | ||
error.message.includes( | ||
'Lit is in dev mode. Not recommended for production!', | ||
), | ||
] | ||
|
||
const throwMessage = (type: any, message: any) => { | ||
// eslint-disable-next-line local-rules/no-uncategorized-errors | ||
const error = new Error(`${type}${message}`) | ||
if (!ignoreList.reduce((acc, item) => acc || item(error), false)) { | ||
throw error | ||
} | ||
} | ||
const throwWarning = (message: any) => throwMessage('warn: ', message) | ||
const throwError = (message: any) => throwMessage('error: ', message) | ||
|
||
vi.spyOn(console, 'warn').mockImplementation(throwWarning) | ||
vi.spyOn(console, 'error').mockImplementation(throwError) | ||
|
||
expect.extend({ | ||
toMatchPaths(regex: RegExp, paths: string[]) { | ||
const matched = paths.map((p) => !!p.match(regex)) | ||
|
||
const pass = matched.every(Boolean) | ||
const failures = paths.filter((_, i) => (pass ? matched[i] : !matched[i])) | ||
const message = () => dedent`Expected ${regex} to ${pass ? 'not ' : ''}match all strings. | ||
Failures:${['', ...failures].join('\n - ')}` | ||
return { | ||
pass, | ||
message, | ||
} | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { resolve } from 'node:path' | ||
import { defineConfig, defineWorkspace } from 'vitest/config' | ||
|
||
export default defineWorkspace(['packages/*/vitest.config.ts']) | ||
|
||
/** | ||
* CircleCI reports the wrong number of threads to Node.js, so we need to set it manually. | ||
* Unit tests are running with the xlarge resource class, which has 8 vCPUs. | ||
* @see https://jahed.dev/2022/11/20/fixing-node-js-multi-threading-on-circleci/ | ||
* @see https://vitest.dev/config/#pooloptions-threads-maxthreads | ||
* @see https://circleci.com/docs/configuration-reference/#x86 | ||
* @see .circleci/config.yml#L214 | ||
*/ | ||
const threadCount = process.env.CI ? 8 : undefined | ||
|
||
export const vitestCommonConfig = defineConfig({ | ||
test: { | ||
passWithNoTests: true, | ||
clearMocks: true, | ||
setupFiles: [resolve(__dirname, './vitest-setup.ts')], | ||
globals: true, | ||
testTimeout: 10000, | ||
environment: 'node', | ||
poolOptions: { | ||
threads: { | ||
minThreads: threadCount, | ||
maxThreads: threadCount, | ||
}, | ||
}, | ||
}, | ||
}) |