@rstest/core 0.3.0 → 0.3.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/12.js +2 -1
- package/dist/223.js +25 -5
- package/dist/33.js +2 -1
- package/dist/971.js +2 -1
- package/dist/index.js +20 -8
- package/dist-types/index.d.ts +8 -2
- package/dist-types/worker.d.ts +8 -2
- package/package.json +1 -1
package/dist/12.js
CHANGED
|
@@ -588,12 +588,13 @@ export const __webpack_modules__ = {
|
|
|
588
588
|
});
|
|
589
589
|
this.reporters = reporters;
|
|
590
590
|
this.snapshotManager = snapshotManager;
|
|
591
|
-
this.version = "0.3.
|
|
591
|
+
this.version = "0.3.1";
|
|
592
592
|
this.rootPath = rootPath;
|
|
593
593
|
this.originalConfig = userConfig;
|
|
594
594
|
this.normalizedConfig = rstestConfig;
|
|
595
595
|
this.projects = projects.length ? projects.map((project)=>{
|
|
596
596
|
const config = (0, src_config.wX)(project.config);
|
|
597
|
+
config.isolate = rstestConfig.isolate;
|
|
597
598
|
return {
|
|
598
599
|
configFilePath: project.configFilePath,
|
|
599
600
|
rootPath: config.root,
|
package/dist/223.js
CHANGED
|
@@ -51,7 +51,7 @@ export const __webpack_modules__ = {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
async function resolveProjects({ config, root, options }) {
|
|
54
|
-
if (!config.projects
|
|
54
|
+
if (!config.projects) return [];
|
|
55
55
|
const getDefaultProjectName = (dir)=>{
|
|
56
56
|
const pkgJsonPath = (0, pathe__WEBPACK_IMPORTED_MODULE_1__.resolve)(dir, 'package.json');
|
|
57
57
|
const name = (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync)(pkgJsonPath) ? JSON.parse((0, node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync)(pkgJsonPath, 'utf-8')).name : '';
|
|
@@ -72,8 +72,21 @@ export const __webpack_modules__ = {
|
|
|
72
72
|
};
|
|
73
73
|
return (0, tinyglobby__WEBPACK_IMPORTED_MODULE_4__.glob)(patterns, globOptions);
|
|
74
74
|
};
|
|
75
|
-
const
|
|
76
|
-
|
|
75
|
+
const formatRootStr = (rootStr)=>rootStr.replace('<rootDir>', root);
|
|
76
|
+
const { projectPaths, projectPatterns, projectConfigs } = (config.projects || []).reduce((total, p)=>{
|
|
77
|
+
if ('object' == typeof p) {
|
|
78
|
+
const projectRoot = p.root ? formatRootStr(p.root) : root;
|
|
79
|
+
total.projectConfigs.push({
|
|
80
|
+
config: {
|
|
81
|
+
root: projectRoot,
|
|
82
|
+
name: p.name ? p.name : getDefaultProjectName(projectRoot),
|
|
83
|
+
...p
|
|
84
|
+
},
|
|
85
|
+
configFilePath: void 0
|
|
86
|
+
});
|
|
87
|
+
return total;
|
|
88
|
+
}
|
|
89
|
+
const projectStr = formatRootStr(p);
|
|
77
90
|
if ((0, tinyglobby__WEBPACK_IMPORTED_MODULE_4__.ey)(projectStr)) total.projectPatterns.push(projectStr);
|
|
78
91
|
else {
|
|
79
92
|
const absolutePath = (0, _utils__WEBPACK_IMPORTED_MODULE_3__.FI)(root, projectStr);
|
|
@@ -83,7 +96,8 @@ export const __webpack_modules__ = {
|
|
|
83
96
|
return total;
|
|
84
97
|
}, {
|
|
85
98
|
projectPaths: [],
|
|
86
|
-
projectPatterns: []
|
|
99
|
+
projectPatterns: [],
|
|
100
|
+
projectConfigs: []
|
|
87
101
|
});
|
|
88
102
|
projectPaths.push(...await globProjects(projectPatterns));
|
|
89
103
|
const projects = await Promise.all(projectPaths.map(async (project)=>{
|
|
@@ -99,7 +113,13 @@ export const __webpack_modules__ = {
|
|
|
99
113
|
config,
|
|
100
114
|
configFilePath
|
|
101
115
|
};
|
|
102
|
-
}));
|
|
116
|
+
})).then((projects)=>(0, _utils__WEBPACK_IMPORTED_MODULE_3__.zz)(projects.concat(projectConfigs), options));
|
|
117
|
+
if (!projects.length) {
|
|
118
|
+
let errorMsg = `No projects found, please make sure you have at least one valid project.
|
|
119
|
+
${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.gray('projects:')} ${JSON.stringify(config.projects, null, 2)}`;
|
|
120
|
+
if (options.project) errorMsg += `\n${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.gray('projectName filter:')} ${JSON.stringify(options.project, null, 2)}`;
|
|
121
|
+
throw errorMsg;
|
|
122
|
+
}
|
|
103
123
|
const names = new Set();
|
|
104
124
|
projects.forEach((project)=>{
|
|
105
125
|
if (names.has(project.config.name)) {
|
package/dist/33.js
CHANGED
package/dist/971.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -2677,7 +2677,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2677
2677
|
const applyCommonOptions = (cli)=>{
|
|
2678
2678
|
cli.option('-c, --config <config>', 'Specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'Specify the loader to load the config file, can be `jiti` or `native`', {
|
|
2679
2679
|
default: 'jiti'
|
|
2680
|
-
}).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('--isolate', 'Run tests in an isolated environment').option('--include <include>', 'Match test files').option('--exclude <exclude>', 'Exclude files from test').option('-u, --update', 'Update snapshot files').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('--reporter <reporter>', 'Specify the reporter to use').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--hookTimeout <value>', 'Timeout of hook in milliseconds').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test');
|
|
2680
|
+
}).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('--isolate', 'Run tests in an isolated environment').option('--include <include>', 'Match test files').option('--exclude <exclude>', 'Exclude files from test').option('-u, --update', 'Update snapshot files').option('--project <name>', 'Run only projects that match the name, can be a full name or wildcards pattern').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('--reporter <reporter>', 'Specify the reporter to use').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--hookTimeout <value>', 'Timeout of hook in milliseconds').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test');
|
|
2681
2681
|
};
|
|
2682
2682
|
const runRest = async ({ options, filters, command })=>{
|
|
2683
2683
|
let rstest;
|
|
@@ -2709,7 +2709,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2709
2709
|
function setupCommands() {
|
|
2710
2710
|
const cli = dist('rstest');
|
|
2711
2711
|
cli.help();
|
|
2712
|
-
cli.version("0.3.
|
|
2712
|
+
cli.version("0.3.1");
|
|
2713
2713
|
applyCommonOptions(cli);
|
|
2714
2714
|
cli.command('[...filters]', 'run tests').option('-w, --watch', 'Run tests in watch mode').action(async (filters, options)=>{
|
|
2715
2715
|
(0, prepare.N)();
|
|
@@ -2779,7 +2779,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2779
2779
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
2780
2780
|
}
|
|
2781
2781
|
function showRstest() {
|
|
2782
|
-
_utils_logger__WEBPACK_IMPORTED_MODULE_0__.vF.greet(" Rstest v0.3.
|
|
2782
|
+
_utils_logger__WEBPACK_IMPORTED_MODULE_0__.vF.greet(" Rstest v0.3.1");
|
|
2783
2783
|
_utils_logger__WEBPACK_IMPORTED_MODULE_0__.vF.log('');
|
|
2784
2784
|
}
|
|
2785
2785
|
},
|
|
@@ -3070,6 +3070,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3070
3070
|
_o: ()=>logger._o,
|
|
3071
3071
|
pr: ()=>getSetupFiles,
|
|
3072
3072
|
Kv: ()=>helper.Kv,
|
|
3073
|
+
zz: ()=>filterProjects,
|
|
3073
3074
|
mT: ()=>logger.mT,
|
|
3074
3075
|
t: ()=>constants.t,
|
|
3075
3076
|
kV: ()=>helper.kV,
|
|
@@ -3097,11 +3098,22 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3097
3098
|
});
|
|
3098
3099
|
});
|
|
3099
3100
|
};
|
|
3101
|
+
const filterProjects = (projects, options)=>{
|
|
3102
|
+
if (options.project) {
|
|
3103
|
+
const regexes = (0, helper.bg)(options.project).map((pattern)=>{
|
|
3104
|
+
const isNeg = pattern.startsWith('!');
|
|
3105
|
+
const escaped = (isNeg ? pattern.slice(1) : pattern).split('*').map((part)=>part.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*');
|
|
3106
|
+
return new RegExp(isNeg ? `^(?!${escaped})` : `^${escaped}$`);
|
|
3107
|
+
});
|
|
3108
|
+
return projects.filter((proj)=>regexes.some((re)=>re.test(proj.config.name)));
|
|
3109
|
+
}
|
|
3110
|
+
return projects;
|
|
3111
|
+
};
|
|
3100
3112
|
const hasInSourceTestCode = (code)=>code.includes('import.meta.rstest');
|
|
3101
3113
|
const formatTestEntryName = (name)=>name.replace(/\.*[/\\]/g, '_').replace(/\./g, '~');
|
|
3102
|
-
const getTestEntries = async ({ include, exclude,
|
|
3114
|
+
const getTestEntries = async ({ include, exclude, rootPath, projectRoot, fileFilters, includeSource })=>{
|
|
3103
3115
|
const testFiles = await (0, dist.glob)(include, {
|
|
3104
|
-
cwd:
|
|
3116
|
+
cwd: projectRoot,
|
|
3105
3117
|
absolute: true,
|
|
3106
3118
|
ignore: exclude,
|
|
3107
3119
|
dot: true,
|
|
@@ -3109,7 +3121,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3109
3121
|
});
|
|
3110
3122
|
if (includeSource?.length) {
|
|
3111
3123
|
const sourceFiles = await (0, dist.glob)(includeSource, {
|
|
3112
|
-
cwd:
|
|
3124
|
+
cwd: projectRoot,
|
|
3113
3125
|
absolute: true,
|
|
3114
3126
|
ignore: exclude,
|
|
3115
3127
|
dot: true,
|
|
@@ -3124,8 +3136,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3124
3136
|
}
|
|
3125
3137
|
}));
|
|
3126
3138
|
}
|
|
3127
|
-
return Object.fromEntries(filterFiles(testFiles, fileFilters,
|
|
3128
|
-
const relativePath = external_pathe_["default"].relative(
|
|
3139
|
+
return Object.fromEntries(filterFiles(testFiles, fileFilters, rootPath).map((entry)=>{
|
|
3140
|
+
const relativePath = external_pathe_["default"].relative(rootPath, entry);
|
|
3129
3141
|
return [
|
|
3130
3142
|
formatTestEntryName(relativePath),
|
|
3131
3143
|
entry
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1577,6 +1577,10 @@ declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>)
|
|
|
1577
1577
|
|
|
1578
1578
|
declare type NormalizedProcedure_2<T extends Procedure_2> = (...args: Parameters<T>) => ReturnType<T>;
|
|
1579
1579
|
|
|
1580
|
+
declare type NormalizedProjectConfig = Required<Omit<RstestConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
|
|
1581
|
+
[key in OptionalKeys]?: RstestConfig[key];
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1580
1584
|
declare interface OldPlugin {
|
|
1581
1585
|
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
1582
1586
|
test: Test;
|
|
@@ -1650,12 +1654,14 @@ declare type Procedure = (...args: any[]) => any;
|
|
|
1650
1654
|
|
|
1651
1655
|
declare type Procedure_2 = (...args: any[]) => any;
|
|
1652
1656
|
|
|
1657
|
+
declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate'>;
|
|
1658
|
+
|
|
1653
1659
|
declare type ProjectContext = {
|
|
1654
1660
|
name: string;
|
|
1655
1661
|
environmentName: string;
|
|
1656
1662
|
rootPath: string;
|
|
1657
1663
|
configFilePath?: string;
|
|
1658
|
-
normalizedConfig:
|
|
1664
|
+
normalizedConfig: NormalizedProjectConfig;
|
|
1659
1665
|
};
|
|
1660
1666
|
|
|
1661
1667
|
declare type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
|
|
@@ -2353,7 +2359,7 @@ declare type TestPath = string;
|
|
|
2353
2359
|
*
|
|
2354
2360
|
* eg. ['packages/*', 'examples/node/rstest.config.ts']
|
|
2355
2361
|
*/
|
|
2356
|
-
declare type TestProject = string;
|
|
2362
|
+
declare type TestProject = string | ProjectConfig;
|
|
2357
2363
|
|
|
2358
2364
|
export declare type TestResult = {
|
|
2359
2365
|
status: TestResultStatus;
|
package/dist-types/worker.d.ts
CHANGED
|
@@ -1358,6 +1358,10 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
|
|
|
1358
1358
|
|
|
1359
1359
|
declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
|
|
1360
1360
|
|
|
1361
|
+
declare type NormalizedProjectConfig = Required<Omit<RstestConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
|
|
1362
|
+
[key in OptionalKeys]?: RstestConfig[key];
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1361
1365
|
declare interface OldPlugin {
|
|
1362
1366
|
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
1363
1367
|
test: Test;
|
|
@@ -1425,12 +1429,14 @@ declare function printWithType<T>(name: string, value: T, print: (value: T) => s
|
|
|
1425
1429
|
|
|
1426
1430
|
declare type Procedure = (...args: any[]) => any;
|
|
1427
1431
|
|
|
1432
|
+
declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate'>;
|
|
1433
|
+
|
|
1428
1434
|
declare type ProjectContext = {
|
|
1429
1435
|
name: string;
|
|
1430
1436
|
environmentName: string;
|
|
1431
1437
|
rootPath: string;
|
|
1432
1438
|
configFilePath?: string;
|
|
1433
|
-
normalizedConfig:
|
|
1439
|
+
normalizedConfig: NormalizedProjectConfig;
|
|
1434
1440
|
};
|
|
1435
1441
|
|
|
1436
1442
|
declare type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
|
|
@@ -2057,7 +2063,7 @@ declare type TestPath = string;
|
|
|
2057
2063
|
*
|
|
2058
2064
|
* eg. ['packages/*', 'examples/node/rstest.config.ts']
|
|
2059
2065
|
*/
|
|
2060
|
-
declare type TestProject = string;
|
|
2066
|
+
declare type TestProject = string | ProjectConfig;
|
|
2061
2067
|
|
|
2062
2068
|
declare type TestResult = {
|
|
2063
2069
|
status: TestResultStatus;
|