@describe-me/vitest 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-profile.js +1 -0
- package/dist/dom-profile.js +4 -5
- package/dist/environment-profile.d.ts +6 -0
- package/dist/plugin.js +11 -0
- package/dist/set-up-project.d.ts +12 -0
- package/dist/set-up-project.js +39 -0
- package/package.json +3 -3
package/dist/browser-profile.js
CHANGED
package/dist/dom-profile.js
CHANGED
|
@@ -9,16 +9,15 @@ export const domProfile = {
|
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
11
|
setupFile: '@describe-me/vitest/setup-dom',
|
|
12
|
+
// Testing Library would otherwise unmount in its own afterEach, before the
|
|
13
|
+
// closing frame is taken. The adapter unmounts through the recorder instead.
|
|
14
|
+
env: { RTL_SKIP_AUTO_CLEANUP: 'true' },
|
|
12
15
|
configFor({ userConfig, options }) {
|
|
13
16
|
const build = options.styledComponentsBrowserBuild === false
|
|
14
17
|
? undefined
|
|
15
18
|
: styledComponentsBrowserBuild(userConfig.root ?? process.cwd());
|
|
16
19
|
const userTest = userConfig.test;
|
|
17
|
-
const test = {
|
|
18
|
-
// Testing Library would otherwise unmount in its own afterEach, before the
|
|
19
|
-
// closing frame is taken. The adapter unmounts through the recorder instead.
|
|
20
|
-
env: { RTL_SKIP_AUTO_CLEANUP: 'true' },
|
|
21
|
-
};
|
|
20
|
+
const test = {};
|
|
22
21
|
// Vitest stubs CSS imports by default, which would leave every imported
|
|
23
22
|
// stylesheet out of the snapshots. An explicit choice by the user wins.
|
|
24
23
|
if (userTest?.css === undefined) {
|
|
@@ -30,6 +30,12 @@ export interface EnvironmentProfile {
|
|
|
30
30
|
renderModules: Record<NonNullable<DescribeMeOptions['framework']>, RenderModule>;
|
|
31
31
|
/** The setup file that patches interactions and registers the recording hooks. */
|
|
32
32
|
setupFile: string;
|
|
33
|
+
/**
|
|
34
|
+
* Variables the tests of a project with the setup file need. The plugin sets
|
|
35
|
+
* them per project and never in the root's `test.env`, which Vitest hands to
|
|
36
|
+
* every project, also to one without describe-me.
|
|
37
|
+
*/
|
|
38
|
+
env: Record<string, string>;
|
|
33
39
|
/** The rest of the environment's config, built in the plugin's `config` hook. */
|
|
34
40
|
configFor(context: ProfileContext): ProfileConfig;
|
|
35
41
|
}
|
package/dist/plugin.js
CHANGED
|
@@ -13,6 +13,7 @@ import { projectModulePath } from './project-module-path.js';
|
|
|
13
13
|
import { registerExports } from './register-exports.js';
|
|
14
14
|
import DescribeMeReporter from './reporter.js';
|
|
15
15
|
import { RUNTIME_OPTIONS_KEY } from './runtime-options.js';
|
|
16
|
+
import { setUpProject } from './set-up-project.js';
|
|
16
17
|
import { validateRenderFrame } from './validate-render-frame.js';
|
|
17
18
|
/**
|
|
18
19
|
* One-line integration: `plugins: [describeMe()]`.
|
|
@@ -32,6 +33,8 @@ export function describeMe(options = {}) {
|
|
|
32
33
|
// Set by `config()`, which Vite runs before `configResolved` and `resolveId`.
|
|
33
34
|
// Stays null while the plugin is disabled.
|
|
34
35
|
let renderModule = null;
|
|
36
|
+
// The chosen profile, also set by `config()`, for the projects that skip it.
|
|
37
|
+
let projectProfile = null;
|
|
35
38
|
// Known once Vite has resolved its config. Vitest always serves; a production
|
|
36
39
|
// build that shares the config must not carry the export registration.
|
|
37
40
|
let root = '';
|
|
@@ -59,6 +62,7 @@ export function describeMe(options = {}) {
|
|
|
59
62
|
const provide = { [RUNTIME_OPTIONS_KEY]: runtimeOptions };
|
|
60
63
|
const profile = await loadProfile(environment);
|
|
61
64
|
renderModule = profile.renderModules[framework];
|
|
65
|
+
projectProfile = profile;
|
|
62
66
|
const { config, setupWarnings } = profile.configFor({ userConfig, options, renderModule });
|
|
63
67
|
const reporter = new DescribeMeReporter({
|
|
64
68
|
outDir,
|
|
@@ -76,6 +80,13 @@ export function describeMe(options = {}) {
|
|
|
76
80
|
test: { setupFiles: [profile.setupFile], ...config.test, reporters, provide },
|
|
77
81
|
};
|
|
78
82
|
},
|
|
83
|
+
// Runs for every project the plugin's Vite server serves, also those that
|
|
84
|
+
// share the root's server and so never reach `config()` (see setUpProject).
|
|
85
|
+
configureVitest({ project }) {
|
|
86
|
+
if (projectProfile !== null) {
|
|
87
|
+
setUpProject(project, projectProfile);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
79
90
|
async resolveId(source, importer) {
|
|
80
91
|
if (!enabled || renderModule === null || source !== renderModule.original) {
|
|
81
92
|
return null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TestProject } from 'vitest/node';
|
|
2
|
+
import type { EnvironmentProfile } from './environment-profile.js';
|
|
3
|
+
/**
|
|
4
|
+
* Gives a project the profile's setup file, when it lacks it, and the
|
|
5
|
+
* profile's variables. In Vitest 5 a project that shares the root's Vite
|
|
6
|
+
* server inherits the root config as it was before the plugin's `config`
|
|
7
|
+
* hook, so it gets the render redirect but not the setup file, and records
|
|
8
|
+
* nothing. The file goes last, as in the root config. Only projects with the
|
|
9
|
+
* setup file get the variables, so one without describe-me keeps Testing
|
|
10
|
+
* Library's own cleanup.
|
|
11
|
+
*/
|
|
12
|
+
export declare function setUpProject(project: TestProject, profile: EnvironmentProfile): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
function resolveFrom(root, specifier) {
|
|
5
|
+
try {
|
|
6
|
+
return createRequire(join(root, 'package.json')).resolve(specifier);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function realPathOf(file) {
|
|
13
|
+
try {
|
|
14
|
+
return realpathSync(file);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return file;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gives a project the profile's setup file, when it lacks it, and the
|
|
22
|
+
* profile's variables. In Vitest 5 a project that shares the root's Vite
|
|
23
|
+
* server inherits the root config as it was before the plugin's `config`
|
|
24
|
+
* hook, so it gets the render redirect but not the setup file, and records
|
|
25
|
+
* nothing. The file goes last, as in the root config. Only projects with the
|
|
26
|
+
* setup file get the variables, so one without describe-me keeps Testing
|
|
27
|
+
* Library's own cleanup.
|
|
28
|
+
*/
|
|
29
|
+
export function setUpProject(project, profile) {
|
|
30
|
+
const file = resolveFrom(project.config.root, profile.setupFile);
|
|
31
|
+
if (file === null) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const real = realPathOf(file);
|
|
35
|
+
if (!project.config.setupFiles.some((entry) => realPathOf(entry) === real)) {
|
|
36
|
+
project.config.setupFiles.push(file);
|
|
37
|
+
}
|
|
38
|
+
project.config.env = { ...project.config.env, ...profile.env };
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@describe-me/vitest",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Living component documentation from your Vitest tests: the Vitest plugin, setup files and reporter of describe-me",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitest",
|
|
@@ -71,13 +71,13 @@
|
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"picomatch": "^4.0.3",
|
|
73
73
|
"std-env": "^4.0.0",
|
|
74
|
-
"@describe-me/core": "^0.6.
|
|
74
|
+
"@describe-me/core": "^0.6.1"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"vitest": "^4.0.0 || ^5.0.0",
|
|
78
78
|
"typescript": "^5.0.0 || ^6.0.0",
|
|
79
79
|
"@testing-library/user-event": "^14.0.0",
|
|
80
|
-
"describe-me": "^0.6.
|
|
80
|
+
"describe-me": "^0.6.1"
|
|
81
81
|
},
|
|
82
82
|
"peerDependenciesMeta": {
|
|
83
83
|
"typescript": {
|