@rstest/core 0.8.0 → 0.8.2
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/LICENSE.md +0 -200
- package/dist/0~130.js +7 -9
- package/dist/0~1472.js +8 -12
- package/dist/0~2173.js +102 -67
- package/dist/0~2255.js +2 -2
- package/dist/0~3919.js +1 -1
- package/dist/0~4403.js +4 -4
- package/dist/0~5835.js +3 -3
- package/dist/0~6588.js +4 -7
- package/dist/0~6923.js +3 -3
- package/dist/0~7583.js +8 -9
- package/dist/0~7882.js +36 -723
- package/dist/0~8426.js +5 -7
- package/dist/0~89.js +21 -18
- package/dist/0~9348.js +1 -2
- package/dist/0~9634.js +24 -13
- package/dist/1157.js +172 -42
- package/dist/1157.js.LICENSE.txt +21 -0
- package/dist/1294.js +1 -1
- package/dist/{2672.js → 3160.js} +312 -8
- package/dist/487.js +3 -3
- package/dist/5734.js +2 -5
- package/dist/6151.js +210 -11
- package/dist/6973.js +5 -7
- package/dist/7011.js +19 -0
- package/dist/9131.js +1381 -71
- package/dist/browser-runtime/2~907.js +0 -2
- package/dist/browser-runtime/389.js +628 -24
- package/dist/browser-runtime/index.d.ts +263 -118
- package/dist/browser-runtime/rslib-runtime.js +0 -2
- package/dist/browser.d.ts +324 -119
- package/dist/browser.js +2 -7
- package/dist/globalSetupWorker.js +2 -4
- package/dist/index.d.ts +274 -117
- package/dist/mockRuntimeCode.js +92 -0
- package/dist/rslib-runtime.js +0 -27
- package/dist/worker.d.ts +99 -110
- package/dist/worker.js +3 -5
- package/package.json +2 -3
- package/dist/3278.js +0 -318
- package/dist/browser-runtime/2~907.js.map +0 -1
- package/dist/browser-runtime/389.js.map +0 -1
- package/dist/browser-runtime/rslib-runtime.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -312,11 +312,14 @@ declare type BrowserModeConfig = {
|
|
|
312
312
|
*/
|
|
313
313
|
declare type BrowserName = 'chromium' | 'firefox' | 'webkit';
|
|
314
314
|
|
|
315
|
-
declare type BuiltInReporterNames =
|
|
315
|
+
declare type BuiltInReporterNames = 'default' | 'verbose' | 'md' | 'github-actions' | 'junit';
|
|
316
316
|
|
|
317
317
|
declare type BuiltinReporterOptions = {
|
|
318
318
|
default: DefaultReporterOptions;
|
|
319
319
|
verbose: VerboseReporterOptions;
|
|
320
|
+
md: MdReporterOptions;
|
|
321
|
+
'github-actions': Record<string, unknown>;
|
|
322
|
+
junit: Record<string, unknown>;
|
|
320
323
|
};
|
|
321
324
|
|
|
322
325
|
declare type ChaiConfig = Partial<Omit<typeof config, 'useProxy' | 'proxyExcludedKeys' | 'deepEqual'>>;
|
|
@@ -359,6 +362,17 @@ declare type CommonOptions = {
|
|
|
359
362
|
config?: string;
|
|
360
363
|
configLoader?: LoadConfigOptions['loader'];
|
|
361
364
|
globals?: boolean;
|
|
365
|
+
/**
|
|
366
|
+
* Pool options.
|
|
367
|
+
* - `string`: shorthand for `{ type: string }` (from `--pool` flag)
|
|
368
|
+
* - `object`: detailed pool config (from `--pool.*` options)
|
|
369
|
+
*/
|
|
370
|
+
pool?: string | {
|
|
371
|
+
type?: string;
|
|
372
|
+
maxWorkers?: string | number;
|
|
373
|
+
minWorkers?: string | number;
|
|
374
|
+
execArgv?: string[] | string;
|
|
375
|
+
};
|
|
362
376
|
/**
|
|
363
377
|
* Browser mode options.
|
|
364
378
|
* - `boolean`: shorthand for `{ enabled: boolean }` (from `--browser` flag)
|
|
@@ -397,6 +411,7 @@ declare type CommonOptions = {
|
|
|
397
411
|
hideSkippedTests?: boolean;
|
|
398
412
|
hideSkippedTestFiles?: boolean;
|
|
399
413
|
bail?: number | boolean;
|
|
414
|
+
shard?: string;
|
|
400
415
|
};
|
|
401
416
|
|
|
402
417
|
declare type CompareKeys = ((a: string, b: string) => number) | null | undefined;
|
|
@@ -422,6 +437,8 @@ declare interface Constructable {
|
|
|
422
437
|
new (...args: any[]): any;
|
|
423
438
|
}
|
|
424
439
|
|
|
440
|
+
declare type Constructor<T = any> = new (...args: any[]) => T;
|
|
441
|
+
|
|
425
442
|
/**
|
|
426
443
|
* Base class for writing content
|
|
427
444
|
*/
|
|
@@ -699,40 +716,6 @@ declare class DefaultMap<
|
|
|
699
716
|
get(key: K): V;
|
|
700
717
|
}
|
|
701
718
|
|
|
702
|
-
declare class DefaultReporter implements Reporter {
|
|
703
|
-
protected rootPath: string;
|
|
704
|
-
protected config: NormalizedConfig;
|
|
705
|
-
private options;
|
|
706
|
-
protected statusRenderer: StatusRenderer | undefined;
|
|
707
|
-
private testState;
|
|
708
|
-
constructor({ rootPath, options, config, testState, }: {
|
|
709
|
-
rootPath: string;
|
|
710
|
-
config: NormalizedConfig;
|
|
711
|
-
options: DefaultReporterOptions;
|
|
712
|
-
testState: RstestTestState;
|
|
713
|
-
});
|
|
714
|
-
/**
|
|
715
|
-
* Lazily create StatusRenderer on first test file start.
|
|
716
|
-
* This avoids intercepting stdout/stderr before tests actually begin,
|
|
717
|
-
* ensuring early errors (like missing Playwright browsers) remain visible.
|
|
718
|
-
*/
|
|
719
|
-
private ensureStatusRenderer;
|
|
720
|
-
onTestFileStart(): void;
|
|
721
|
-
onTestFileResult(test: TestFileResult): void;
|
|
722
|
-
onTestCaseResult(): void;
|
|
723
|
-
onUserConsoleLog(log: UserConsoleLog): void;
|
|
724
|
-
onExit(): Promise<void>;
|
|
725
|
-
onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, unhandledErrors, }: {
|
|
726
|
-
results: TestFileResult[];
|
|
727
|
-
testResults: TestResult[];
|
|
728
|
-
duration: Duration;
|
|
729
|
-
snapshotSummary: SnapshotSummary;
|
|
730
|
-
getSourcemap: GetSourcemap;
|
|
731
|
-
unhandledErrors?: Error[];
|
|
732
|
-
filterRerunTestPaths?: string[];
|
|
733
|
-
}): Promise<void>;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
719
|
declare type DefaultReporterOptions = {
|
|
737
720
|
/**
|
|
738
721
|
* prints out summary of all tests
|
|
@@ -1077,26 +1060,6 @@ declare function getMatcherUtils(): {
|
|
|
1077
1060
|
|
|
1078
1061
|
declare type GetSourcemap = (sourcePath: string) => Promise<SourceMapInput | null>;
|
|
1079
1062
|
|
|
1080
|
-
declare class GithubActionsReporter {
|
|
1081
|
-
private onWritePath;
|
|
1082
|
-
private rootPath;
|
|
1083
|
-
constructor({ options, rootPath, }: {
|
|
1084
|
-
rootPath: string;
|
|
1085
|
-
options: {
|
|
1086
|
-
onWritePath: (path: string) => string;
|
|
1087
|
-
};
|
|
1088
|
-
});
|
|
1089
|
-
private log;
|
|
1090
|
-
onTestRunEnd({ results, testResults, getSourcemap, }: {
|
|
1091
|
-
results: TestFileResult[];
|
|
1092
|
-
testResults: TestResult[];
|
|
1093
|
-
duration: Duration;
|
|
1094
|
-
snapshotSummary: SnapshotSummary;
|
|
1095
|
-
getSourcemap: GetSourcemap;
|
|
1096
|
-
filterRerunTestPaths?: string[];
|
|
1097
|
-
}): Promise<void>;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
1063
|
declare interface HtmlOptions {
|
|
1101
1064
|
verbose: boolean;
|
|
1102
1065
|
skipEmpty: boolean;
|
|
@@ -1530,28 +1493,6 @@ declare type JsonOptions = FileOptions;
|
|
|
1530
1493
|
|
|
1531
1494
|
declare type JsonSummaryOptions = FileOptions;
|
|
1532
1495
|
|
|
1533
|
-
declare class JUnitReporter implements Reporter {
|
|
1534
|
-
private rootPath;
|
|
1535
|
-
private outputPath?;
|
|
1536
|
-
constructor({ rootPath, options: { outputPath }, }: {
|
|
1537
|
-
rootPath: string;
|
|
1538
|
-
options?: {
|
|
1539
|
-
outputPath?: string;
|
|
1540
|
-
};
|
|
1541
|
-
});
|
|
1542
|
-
private sanitizeXml;
|
|
1543
|
-
private escapeXml;
|
|
1544
|
-
private createJUnitTestCase;
|
|
1545
|
-
private createJUnitTestSuite;
|
|
1546
|
-
private generateJUnitXml;
|
|
1547
|
-
onTestRunEnd({ results, testResults, duration, getSourcemap, }: {
|
|
1548
|
-
getSourcemap: GetSourcemap;
|
|
1549
|
-
results: TestFileResult[];
|
|
1550
|
-
testResults: TestResult[];
|
|
1551
|
-
duration: Duration;
|
|
1552
|
-
}): Promise<void>;
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
1496
|
declare interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
|
|
1556
1497
|
|
|
1557
1498
|
declare interface LcovOptions extends FileOptions, ProjectOptions {}
|
|
@@ -1650,12 +1591,107 @@ declare interface MatcherState_2 extends MatcherState {
|
|
|
1650
1591
|
snapshotState: SnapshotState;
|
|
1651
1592
|
}
|
|
1652
1593
|
|
|
1594
|
+
declare type MaybeMockedDeep<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
1595
|
+
|
|
1596
|
+
declare type MaybePartiallyMocked<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
1597
|
+
|
|
1598
|
+
declare type MaybePartiallyMockedDeep<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
1599
|
+
|
|
1653
1600
|
declare type MaybePromise<T> = T | Promise<T>;
|
|
1654
1601
|
|
|
1602
|
+
declare type MdReporterOptions = {
|
|
1603
|
+
/**
|
|
1604
|
+
* Output detail level preset.
|
|
1605
|
+
* - `'normal'`: balanced output with code frames, repro commands, and candidate files
|
|
1606
|
+
* - `'compact'`: minimal output without code frames, candidate files, or full stack traces
|
|
1607
|
+
* - `'full'`: verbose output including console logs and environment info
|
|
1608
|
+
* @default 'normal'
|
|
1609
|
+
*/
|
|
1610
|
+
preset?: 'normal' | 'compact' | 'full';
|
|
1611
|
+
/**
|
|
1612
|
+
* Header section controls.
|
|
1613
|
+
* - `false`: omit all header extras (runtime/env)
|
|
1614
|
+
* - `true`: include all default header extras
|
|
1615
|
+
* - object form: toggle individual parts
|
|
1616
|
+
* @default { env: true }
|
|
1617
|
+
*/
|
|
1618
|
+
header?: boolean | {
|
|
1619
|
+
env?: boolean;
|
|
1620
|
+
};
|
|
1621
|
+
/**
|
|
1622
|
+
* Reproduction command controls.
|
|
1623
|
+
* - `false`: omit reproduction commands
|
|
1624
|
+
* - `'file'`: only include the test file path
|
|
1625
|
+
* - `'file+name'`: include both file path and `--testNamePattern`
|
|
1626
|
+
* - `true`: same as `'file+name'`
|
|
1627
|
+
* @default 'file+name'
|
|
1628
|
+
*/
|
|
1629
|
+
reproduction?: boolean | 'file' | 'file+name';
|
|
1630
|
+
/**
|
|
1631
|
+
* Failure output controls.
|
|
1632
|
+
* @default { max: 50 }
|
|
1633
|
+
*/
|
|
1634
|
+
failures?: {
|
|
1635
|
+
max?: number;
|
|
1636
|
+
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Code frame controls.
|
|
1639
|
+
* - `false`: disable code frames
|
|
1640
|
+
* - `true`: enable with default line window
|
|
1641
|
+
* - object form: customize line window
|
|
1642
|
+
* @default { linesAbove: 2, linesBelow: 2 }
|
|
1643
|
+
*/
|
|
1644
|
+
codeFrame?: boolean | {
|
|
1645
|
+
linesAbove?: number;
|
|
1646
|
+
linesBelow?: number;
|
|
1647
|
+
};
|
|
1648
|
+
/**
|
|
1649
|
+
* Stack output controls.
|
|
1650
|
+
* - `false`: omit stack info
|
|
1651
|
+
* - `'top'`: include only the top frame
|
|
1652
|
+
* - `number`: include up to N stack frames
|
|
1653
|
+
* - `'full'`: include a large default number of stack frames
|
|
1654
|
+
* @default 'top'
|
|
1655
|
+
*/
|
|
1656
|
+
stack?: number | false | 'full' | 'top';
|
|
1657
|
+
/**
|
|
1658
|
+
* Candidate files controls (best-effort files extracted from stack traces).
|
|
1659
|
+
* - `false`: omit candidate files
|
|
1660
|
+
* - `true`: enable with defaults
|
|
1661
|
+
* - object form: customize max items
|
|
1662
|
+
* @default { max: 5 }
|
|
1663
|
+
*/
|
|
1664
|
+
candidateFiles?: boolean | {
|
|
1665
|
+
max?: number;
|
|
1666
|
+
};
|
|
1667
|
+
/**
|
|
1668
|
+
* Console output controls.
|
|
1669
|
+
* - `false`: omit console logs
|
|
1670
|
+
* - `true`: include console logs with defaults
|
|
1671
|
+
* - object form: customize limits
|
|
1672
|
+
* @default { maxLogsPerTestPath: 10, maxCharsPerEntry: 500 }
|
|
1673
|
+
*/
|
|
1674
|
+
console?: boolean | {
|
|
1675
|
+
maxLogsPerTestPath?: number;
|
|
1676
|
+
maxCharsPerEntry?: number;
|
|
1677
|
+
};
|
|
1678
|
+
/**
|
|
1679
|
+
* Error section controls.
|
|
1680
|
+
* @default { unhandled: true }
|
|
1681
|
+
*/
|
|
1682
|
+
errors?: boolean | {
|
|
1683
|
+
unhandled?: boolean;
|
|
1684
|
+
};
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1655
1687
|
export declare const mergeProjectConfig: (...configs: ProjectConfig[]) => ProjectConfig;
|
|
1656
1688
|
|
|
1657
1689
|
export declare const mergeRstestConfig: (...configs: RstestConfig[]) => RstestConfig;
|
|
1658
1690
|
|
|
1691
|
+
declare type Methods<T> = {
|
|
1692
|
+
[K in keyof T]: T[K] extends MockProcedure ? K : never;
|
|
1693
|
+
}[keyof T];
|
|
1694
|
+
|
|
1659
1695
|
export declare interface Mock<T extends FunctionLike = FunctionLike> extends MockInstance_2<T> {
|
|
1660
1696
|
new (...args: Parameters<T>): ReturnType<T>;
|
|
1661
1697
|
(...args: Parameters<T>): ReturnType<T>;
|
|
@@ -1804,6 +1840,31 @@ declare type MockContext_2<T extends FunctionLike = FunctionLike> = {
|
|
|
1804
1840
|
settledResults: MockSettledResult_2<Awaited<ReturnType<T>>>[];
|
|
1805
1841
|
};
|
|
1806
1842
|
|
|
1843
|
+
export declare type Mocked<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
1844
|
+
|
|
1845
|
+
declare type MockedClass<T extends Constructor> = Mock<(...args: ConstructorParameters<T>) => InstanceType<T>> & {
|
|
1846
|
+
new (...args: ConstructorParameters<T>): InstanceType<T>;
|
|
1847
|
+
prototype: InstanceType<T>;
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1850
|
+
declare type MockedFunction<T extends MockProcedure> = Mock<T> & {
|
|
1851
|
+
[K in keyof T]: T[K];
|
|
1852
|
+
};
|
|
1853
|
+
|
|
1854
|
+
declare type MockedFunctionDeep<T extends MockProcedure> = Mock<T> & MockedObjectDeep<T>;
|
|
1855
|
+
|
|
1856
|
+
declare type MockedObject<T> = {
|
|
1857
|
+
[K in Methods<T>]: T[K] extends MockProcedure ? MockedFunction<T[K]> : T[K];
|
|
1858
|
+
} & {
|
|
1859
|
+
[K in Properties<T>]: T[K];
|
|
1860
|
+
};
|
|
1861
|
+
|
|
1862
|
+
declare type MockedObjectDeep<T> = {
|
|
1863
|
+
[K in Methods<T>]: T[K] extends MockProcedure ? MockedFunctionDeep<T[K]> : T[K];
|
|
1864
|
+
} & {
|
|
1865
|
+
[K in Properties<T>]: MaybeMockedDeep<T[K]>;
|
|
1866
|
+
};
|
|
1867
|
+
|
|
1807
1868
|
declare type MockFactory<T = unknown> = () => MaybePromise<Partial<T>>;
|
|
1808
1869
|
|
|
1809
1870
|
declare type MockFn = <T extends FunctionLike = FunctionLike>(fn?: T) => Mock<T>;
|
|
@@ -2030,6 +2091,37 @@ declare interface MockInstance_2<T extends FunctionLike = FunctionLike> {
|
|
|
2030
2091
|
mockRejectedValueOnce(error: unknown): this;
|
|
2031
2092
|
}
|
|
2032
2093
|
|
|
2094
|
+
/**
|
|
2095
|
+
* Options for rs.mock module mocking.
|
|
2096
|
+
* Supports `{ spy: true }` or `{ mock: true }`.
|
|
2097
|
+
*/
|
|
2098
|
+
declare type MockModuleOptions = {
|
|
2099
|
+
/**
|
|
2100
|
+
* If `true`, the module will be auto-mocked but the original implementations
|
|
2101
|
+
* will be preserved - all exports will be wrapped in spy functions that track calls.
|
|
2102
|
+
*/
|
|
2103
|
+
spy: true;
|
|
2104
|
+
} | {
|
|
2105
|
+
/**
|
|
2106
|
+
* If `true`, the module will be auto-mocked with all exports replaced by mock functions.
|
|
2107
|
+
* Original implementations will NOT be preserved.
|
|
2108
|
+
*/
|
|
2109
|
+
mock: true;
|
|
2110
|
+
};
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Options for mockObject
|
|
2114
|
+
*/
|
|
2115
|
+
declare interface MockOptions {
|
|
2116
|
+
/**
|
|
2117
|
+
* If `true`, the original implementation will be kept.
|
|
2118
|
+
* All methods will call the original implementation, but you can still track the calls.
|
|
2119
|
+
*/
|
|
2120
|
+
spy?: boolean;
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
declare type MockProcedure = (...args: any[]) => any;
|
|
2124
|
+
|
|
2033
2125
|
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
2034
2126
|
|
|
2035
2127
|
declare type MockResult_2<T> = MockResultReturn_2<T> | MockResultThrow_2 | MockResultIncomplete_2;
|
|
@@ -2174,7 +2266,7 @@ export declare const onTestFinished: Rstest['onTestFinished'];
|
|
|
2174
2266
|
|
|
2175
2267
|
declare type OnTestFinishedHandler = (ctx: TestContext) => MaybePromise<void>;
|
|
2176
2268
|
|
|
2177
|
-
declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'chaiConfig' | 'hideSkippedTestFiles' | 'resolveSnapshotPath' | 'extends';
|
|
2269
|
+
declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'chaiConfig' | 'hideSkippedTestFiles' | 'resolveSnapshotPath' | 'extends' | 'shard';
|
|
2178
2270
|
|
|
2179
2271
|
declare interface Options {
|
|
2180
2272
|
logger: {
|
|
@@ -2241,7 +2333,7 @@ declare type Project = {
|
|
|
2241
2333
|
configFilePath?: string;
|
|
2242
2334
|
};
|
|
2243
2335
|
|
|
2244
|
-
export declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage' | 'resolveSnapshotPath' | 'onConsoleLog' | 'hideSkippedTests' | 'hideSkippedTestFiles' | 'bail'>;
|
|
2336
|
+
export declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage' | 'resolveSnapshotPath' | 'onConsoleLog' | 'hideSkippedTests' | 'hideSkippedTestFiles' | 'bail' | 'shard'>;
|
|
2245
2337
|
|
|
2246
2338
|
declare type ProjectConfigAsyncFn = () => Promise<ProjectConfig | NestedProjectConfig>;
|
|
2247
2339
|
|
|
@@ -2273,6 +2365,10 @@ declare type PromisifyAssertion<T> = Promisify<Assertion_2<T>>;
|
|
|
2273
2365
|
|
|
2274
2366
|
declare type PromisifyAssertion_2<T> = Promisify_2<Assertion<T>>;
|
|
2275
2367
|
|
|
2368
|
+
declare type Properties<T> = {
|
|
2369
|
+
[K in keyof T]: T[K] extends MockProcedure ? never : K;
|
|
2370
|
+
}[keyof T];
|
|
2371
|
+
|
|
2276
2372
|
declare interface Range_2 {
|
|
2277
2373
|
start: Location_3;
|
|
2278
2374
|
end: Location_3;
|
|
@@ -2359,13 +2455,6 @@ export declare interface Reporter {
|
|
|
2359
2455
|
onExit?: () => void;
|
|
2360
2456
|
}
|
|
2361
2457
|
|
|
2362
|
-
declare const reportersMap: {
|
|
2363
|
-
default: typeof DefaultReporter;
|
|
2364
|
-
verbose: typeof VerboseReporter;
|
|
2365
|
-
'github-actions': typeof GithubActionsReporter;
|
|
2366
|
-
junit: typeof JUnitReporter;
|
|
2367
|
-
};
|
|
2368
|
-
|
|
2369
2458
|
declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
|
|
2370
2459
|
|
|
2371
2460
|
declare interface ReportOptions {
|
|
@@ -2505,6 +2594,14 @@ export declare interface RstestConfig {
|
|
|
2505
2594
|
* @default 0
|
|
2506
2595
|
*/
|
|
2507
2596
|
bail?: number;
|
|
2597
|
+
/**
|
|
2598
|
+
* Split tests into several shards.
|
|
2599
|
+
* This is useful for running tests in parallel on multiple machines.
|
|
2600
|
+
*/
|
|
2601
|
+
shard?: {
|
|
2602
|
+
count: number;
|
|
2603
|
+
index: number;
|
|
2604
|
+
};
|
|
2508
2605
|
/**
|
|
2509
2606
|
* print console traces when calling any console method.
|
|
2510
2607
|
*
|
|
@@ -2712,6 +2809,74 @@ export declare interface RstestUtilities {
|
|
|
2712
2809
|
* Determines if the given function is a mocked function.
|
|
2713
2810
|
*/
|
|
2714
2811
|
isMockFunction: (fn: any) => fn is MockInstance_2;
|
|
2812
|
+
/**
|
|
2813
|
+
* Deeply mocks properties and methods of a given object
|
|
2814
|
+
* in the same way as `rstest.mock()` mocks module exports.
|
|
2815
|
+
*
|
|
2816
|
+
* @example
|
|
2817
|
+
* ```ts
|
|
2818
|
+
* const original = {
|
|
2819
|
+
* simple: () => 'value',
|
|
2820
|
+
* nested: {
|
|
2821
|
+
* method: () => 'real'
|
|
2822
|
+
* },
|
|
2823
|
+
* prop: 'foo',
|
|
2824
|
+
* }
|
|
2825
|
+
*
|
|
2826
|
+
* const mocked = rstest.mockObject(original)
|
|
2827
|
+
* expect(mocked.simple()).toBe(undefined)
|
|
2828
|
+
* expect(mocked.nested.method()).toBe(undefined)
|
|
2829
|
+
* expect(mocked.prop).toBe('foo')
|
|
2830
|
+
*
|
|
2831
|
+
* mocked.simple.mockReturnValue('mocked')
|
|
2832
|
+
* expect(mocked.simple()).toBe('mocked')
|
|
2833
|
+
*
|
|
2834
|
+
* // With spy option to keep original implementations
|
|
2835
|
+
* const spied = rstest.mockObject(original, { spy: true })
|
|
2836
|
+
* expect(spied.simple()).toBe('value')
|
|
2837
|
+
* expect(spied.simple).toHaveBeenCalled()
|
|
2838
|
+
* ```
|
|
2839
|
+
*
|
|
2840
|
+
* @param value - The object to be mocked
|
|
2841
|
+
* @param options - Mock options
|
|
2842
|
+
* @returns A deeply mocked version of the input object
|
|
2843
|
+
*/
|
|
2844
|
+
mockObject: <T>(value: T, options?: MockOptions) => MaybeMockedDeep<T>;
|
|
2845
|
+
/**
|
|
2846
|
+
* Type helper for TypeScript. Just returns the object that was passed.
|
|
2847
|
+
*
|
|
2848
|
+
* When `partial` is `true` it will expect a `Partial<T>` as a return value.
|
|
2849
|
+
* By default, this will only make TypeScript believe that the first level values are mocked.
|
|
2850
|
+
* You can pass down `{ deep: true }` as a second argument to tell TypeScript
|
|
2851
|
+
* that the whole object is mocked, if it actually is.
|
|
2852
|
+
*
|
|
2853
|
+
* @example
|
|
2854
|
+
* ```ts
|
|
2855
|
+
* import example from './example.js'
|
|
2856
|
+
*
|
|
2857
|
+
* rstest.mock('./example.js')
|
|
2858
|
+
*
|
|
2859
|
+
* test('1 + 1 equals 10', async () => {
|
|
2860
|
+
* rstest.mocked(example.calc).mockReturnValue(10)
|
|
2861
|
+
* expect(example.calc(1, '+', 1)).toBe(10)
|
|
2862
|
+
* })
|
|
2863
|
+
* ```
|
|
2864
|
+
* @param item - Anything that can be mocked
|
|
2865
|
+
* @returns The same item with mocked type
|
|
2866
|
+
*/
|
|
2867
|
+
mocked: (<T>(item: T, deep?: false) => Mocked<T>) & (<T>(item: T, deep: true) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
|
|
2868
|
+
partial?: false;
|
|
2869
|
+
deep?: false;
|
|
2870
|
+
}) => Mocked<T>) & (<T>(item: T, options: {
|
|
2871
|
+
partial?: false;
|
|
2872
|
+
deep: true;
|
|
2873
|
+
}) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
|
|
2874
|
+
partial: true;
|
|
2875
|
+
deep?: false;
|
|
2876
|
+
}) => MaybePartiallyMocked<T>) & (<T>(item: T, options: {
|
|
2877
|
+
partial: true;
|
|
2878
|
+
deep: true;
|
|
2879
|
+
}) => MaybePartiallyMockedDeep<T>);
|
|
2715
2880
|
/**
|
|
2716
2881
|
* Calls `.mockClear()` on all spies.
|
|
2717
2882
|
*/
|
|
@@ -2725,21 +2890,37 @@ export declare interface RstestUtilities {
|
|
|
2725
2890
|
*/
|
|
2726
2891
|
restoreAllMocks: () => RstestUtilities;
|
|
2727
2892
|
/**
|
|
2728
|
-
* Mock a module
|
|
2893
|
+
* Mock a module.
|
|
2894
|
+
*
|
|
2895
|
+
* When called with a factory function, the module will be replaced with the return value of the factory.
|
|
2896
|
+
* When called with `{ spy: true }`, the module will be auto-mocked but the original implementations
|
|
2897
|
+
* will be preserved - all exports will be wrapped in spy functions that track calls.
|
|
2898
|
+
*
|
|
2899
|
+
* @example
|
|
2900
|
+
* ```ts
|
|
2901
|
+
* // Replace module with factory
|
|
2902
|
+
* rs.mock('./module', () => ({ fn: rs.fn() }))
|
|
2903
|
+
*
|
|
2904
|
+
* // Auto-mock with spy mode - keeps original implementations
|
|
2905
|
+
* rs.mock('./module', { spy: true })
|
|
2906
|
+
* ```
|
|
2729
2907
|
*/
|
|
2730
|
-
mock<T = unknown>(moduleName: string | Promise<T>,
|
|
2908
|
+
mock<T = unknown>(moduleName: string | Promise<T>, factoryOrOptions?: MockFactory<T> | MockModuleOptions): void;
|
|
2731
2909
|
/**
|
|
2732
|
-
* Mock a module
|
|
2910
|
+
* Mock a module (CommonJS require)
|
|
2733
2911
|
*/
|
|
2734
|
-
mockRequire: <T = unknown>(moduleName: string,
|
|
2912
|
+
mockRequire: <T = unknown>(moduleName: string, factoryOrOptions?: (() => T) | MockModuleOptions) => void;
|
|
2735
2913
|
/**
|
|
2736
2914
|
* Mock a module, not hoisted.
|
|
2915
|
+
*
|
|
2916
|
+
* When called with `{ spy: true }`, the module will be auto-mocked but the original implementations
|
|
2917
|
+
* will be preserved - all exports will be wrapped in spy functions that track calls.
|
|
2737
2918
|
*/
|
|
2738
|
-
doMock<T = unknown>(moduleName: string | Promise<T>,
|
|
2919
|
+
doMock<T = unknown>(moduleName: string | Promise<T>, factoryOrOptions?: MockFactory<T> | MockModuleOptions): void;
|
|
2739
2920
|
/**
|
|
2740
|
-
* Mock a module, not hoisted.
|
|
2921
|
+
* Mock a module, not hoisted (CommonJS require).
|
|
2741
2922
|
*/
|
|
2742
|
-
doMockRequire: <T = unknown>(moduleName: string,
|
|
2923
|
+
doMockRequire: <T = unknown>(moduleName: string, factoryOrOptions?: (() => T) | MockModuleOptions) => void;
|
|
2743
2924
|
/**
|
|
2744
2925
|
* Hoisted mock function.
|
|
2745
2926
|
*/
|
|
@@ -3024,19 +3205,6 @@ declare interface SourceMapV3 {
|
|
|
3024
3205
|
|
|
3025
3206
|
declare type SourcesIndex = number;
|
|
3026
3207
|
|
|
3027
|
-
declare class StatusRenderer {
|
|
3028
|
-
private rootPath;
|
|
3029
|
-
private renderer;
|
|
3030
|
-
private startTime;
|
|
3031
|
-
private testState;
|
|
3032
|
-
constructor(rootPath: string, state: RstestTestState, logger?: Options['logger']);
|
|
3033
|
-
getContent(): string[];
|
|
3034
|
-
onTestFileStart(): void;
|
|
3035
|
-
onTestCaseResult(): void;
|
|
3036
|
-
onTestFileResult(): void;
|
|
3037
|
-
clear(): void;
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
3208
|
declare function stringify(object: unknown, maxDepth?: number, { maxLength,...options }?: StringifyOptions): string;
|
|
3041
3209
|
|
|
3042
3210
|
declare interface StringifyOptions extends PrettyFormatOptions {
|
|
@@ -3319,17 +3487,6 @@ declare interface UserConsoleLog {
|
|
|
3319
3487
|
type: 'stdout' | 'stderr';
|
|
3320
3488
|
}
|
|
3321
3489
|
|
|
3322
|
-
declare class VerboseReporter extends DefaultReporter {
|
|
3323
|
-
private verboseOptions;
|
|
3324
|
-
constructor({ rootPath, options, config, testState, }: {
|
|
3325
|
-
rootPath: string;
|
|
3326
|
-
config: NormalizedConfig;
|
|
3327
|
-
options: VerboseReporterOptions;
|
|
3328
|
-
testState: RstestTestState;
|
|
3329
|
-
});
|
|
3330
|
-
onTestFileResult(test: TestFileResult): void;
|
|
3331
|
-
}
|
|
3332
|
-
|
|
3333
3490
|
declare type VerboseReporterOptions = Omit<DefaultReporterOptions, 'summary'>;
|
|
3334
3491
|
|
|
3335
3492
|
declare interface Visitor<N extends Node_2 = Node_2> {
|
package/dist/mockRuntimeCode.js
CHANGED
|
@@ -39,6 +39,32 @@ __webpack_require__.rstest_mock = (id, modFactory)=>{
|
|
|
39
39
|
__webpack_require__.rstest_original_modules[id] = requiredModule;
|
|
40
40
|
__webpack_require__.rstest_original_module_factories[id] = __webpack_modules__[id];
|
|
41
41
|
}
|
|
42
|
+
if (modFactory && 'object' == typeof modFactory) {
|
|
43
|
+
const isSpy = true === modFactory.spy;
|
|
44
|
+
const isMock = true === modFactory.mock;
|
|
45
|
+
if (!isSpy && !isMock) throw new Error('[Rstest] rs.mock() options must be { spy: true } or { mock: true }');
|
|
46
|
+
if (!requiredModule) {
|
|
47
|
+
const optionName = isSpy ? 'spy' : 'mock';
|
|
48
|
+
throw new Error(`[Rstest] rs.mock('${id}', { ${optionName}: true }) failed: cannot load original module`);
|
|
49
|
+
}
|
|
50
|
+
const originalModule = requiredModule;
|
|
51
|
+
const isEsModule = true === originalModule.__esModule;
|
|
52
|
+
const mockedModule = globalThis.RSTEST_API?.rstest?.mockObject(originalModule, {
|
|
53
|
+
spy: isSpy
|
|
54
|
+
}) || originalModule;
|
|
55
|
+
const finalModFactory = function(__unused_webpack_module, __webpack_exports__, __webpack_require__1) {
|
|
56
|
+
__webpack_require__1.r(__webpack_exports__);
|
|
57
|
+
for(const key in mockedModule)__webpack_require__1.d(__webpack_exports__, {
|
|
58
|
+
[key]: ()=>mockedModule[key]
|
|
59
|
+
});
|
|
60
|
+
if (!isEsModule && !('default' in mockedModule)) __webpack_require__1.d(__webpack_exports__, {
|
|
61
|
+
default: ()=>mockedModule
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
__webpack_modules__[id] = finalModFactory;
|
|
65
|
+
delete __webpack_module_cache__[id];
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
42
68
|
if ('string' == typeof modFactory || 'number' == typeof modFactory) __webpack_module_cache__[id] = {
|
|
43
69
|
exports: __webpack_require__(modFactory)
|
|
44
70
|
};
|
|
@@ -62,6 +88,28 @@ __webpack_require__.rstest_mock_require = (id, modFactory)=>{
|
|
|
62
88
|
__webpack_require__.rstest_original_modules[id] = requiredModule;
|
|
63
89
|
__webpack_require__.rstest_original_module_factories[id] = __webpack_modules__[id];
|
|
64
90
|
}
|
|
91
|
+
if (modFactory && 'object' == typeof modFactory) {
|
|
92
|
+
const isSpy = true === modFactory.spy;
|
|
93
|
+
const isMock = true === modFactory.mock;
|
|
94
|
+
if (!isSpy && !isMock) throw new Error('[Rstest] rs.mockRequire() options must be { spy: true } or { mock: true }');
|
|
95
|
+
if (!requiredModule) {
|
|
96
|
+
const optionName = isSpy ? 'spy' : 'mock';
|
|
97
|
+
throw new Error(`[Rstest] rs.mockRequire('${id}', { ${optionName}: true }) failed: cannot load original module`);
|
|
98
|
+
}
|
|
99
|
+
const originalModule = requiredModule;
|
|
100
|
+
const isEsModule = true === originalModule.__esModule;
|
|
101
|
+
const mockedModule = globalThis.RSTEST_API?.rstest?.mockObject(originalModule, {
|
|
102
|
+
spy: isSpy
|
|
103
|
+
}) || originalModule;
|
|
104
|
+
if (isEsModule) __webpack_require__.r(mockedModule);
|
|
105
|
+
else if (!('default' in mockedModule)) mockedModule.default = mockedModule;
|
|
106
|
+
__webpack_module_cache__[id] = {
|
|
107
|
+
exports: mockedModule,
|
|
108
|
+
id,
|
|
109
|
+
loaded: true
|
|
110
|
+
};
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
65
113
|
if ('string' == typeof modFactory || 'number' == typeof modFactory) __webpack_module_cache__[id] = {
|
|
66
114
|
exports: __webpack_require__(modFactory)
|
|
67
115
|
};
|
|
@@ -83,6 +131,28 @@ __webpack_require__.rstest_do_mock = (id, modFactory)=>{
|
|
|
83
131
|
__webpack_require__.rstest_original_modules[id] = requiredModule;
|
|
84
132
|
__webpack_require__.rstest_original_module_factories[id] = __webpack_modules__[id];
|
|
85
133
|
}
|
|
134
|
+
if (modFactory && 'object' == typeof modFactory) {
|
|
135
|
+
const isSpy = true === modFactory.spy;
|
|
136
|
+
const isMock = true === modFactory.mock;
|
|
137
|
+
if (!isSpy && !isMock) throw new Error('[Rstest] rs.doMock() options must be { spy: true } or { mock: true }');
|
|
138
|
+
if (!requiredModule) {
|
|
139
|
+
const optionName = isSpy ? 'spy' : 'mock';
|
|
140
|
+
throw new Error(`[Rstest] rs.doMock('${id}', { ${optionName}: true }) failed: cannot load original module`);
|
|
141
|
+
}
|
|
142
|
+
const originalModule = requiredModule;
|
|
143
|
+
const isEsModule = true === originalModule.__esModule;
|
|
144
|
+
const mockedModule = globalThis.RSTEST_API?.rstest?.mockObject(originalModule, {
|
|
145
|
+
spy: isSpy
|
|
146
|
+
}) || originalModule;
|
|
147
|
+
if (isEsModule) __webpack_require__.r(mockedModule);
|
|
148
|
+
else if (!('default' in mockedModule)) mockedModule.default = mockedModule;
|
|
149
|
+
__webpack_module_cache__[id] = {
|
|
150
|
+
exports: mockedModule,
|
|
151
|
+
id,
|
|
152
|
+
loaded: true
|
|
153
|
+
};
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
86
156
|
if ('string' == typeof modFactory || 'number' == typeof modFactory) __webpack_module_cache__[id] = {
|
|
87
157
|
exports: __webpack_require__(modFactory)
|
|
88
158
|
};
|
|
@@ -104,6 +174,28 @@ __webpack_require__.rstest_do_mock_require = (id, modFactory)=>{
|
|
|
104
174
|
__webpack_require__.rstest_original_modules[id] = requiredModule;
|
|
105
175
|
__webpack_require__.rstest_original_module_factories[id] = __webpack_modules__[id];
|
|
106
176
|
}
|
|
177
|
+
if (modFactory && 'object' == typeof modFactory) {
|
|
178
|
+
const isSpy = true === modFactory.spy;
|
|
179
|
+
const isMock = true === modFactory.mock;
|
|
180
|
+
if (!isSpy && !isMock) throw new Error('[Rstest] rs.doMockRequire() options must be { spy: true } or { mock: true }');
|
|
181
|
+
if (!requiredModule) {
|
|
182
|
+
const optionName = isSpy ? 'spy' : 'mock';
|
|
183
|
+
throw new Error(`[Rstest] rs.doMockRequire('${id}', { ${optionName}: true }) failed: cannot load original module`);
|
|
184
|
+
}
|
|
185
|
+
const originalModule = requiredModule;
|
|
186
|
+
const isEsModule = true === originalModule.__esModule;
|
|
187
|
+
const mockedModule = globalThis.RSTEST_API?.rstest?.mockObject(originalModule, {
|
|
188
|
+
spy: isSpy
|
|
189
|
+
}) || originalModule;
|
|
190
|
+
if (isEsModule) __webpack_require__.r(mockedModule);
|
|
191
|
+
else if (!('default' in mockedModule)) mockedModule.default = mockedModule;
|
|
192
|
+
__webpack_module_cache__[id] = {
|
|
193
|
+
exports: mockedModule,
|
|
194
|
+
id,
|
|
195
|
+
loaded: true
|
|
196
|
+
};
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
107
199
|
if ('string' == typeof modFactory || 'number' == typeof modFactory) __webpack_module_cache__[id] = {
|
|
108
200
|
exports: __webpack_require__(modFactory)
|
|
109
201
|
};
|
package/dist/rslib-runtime.js
CHANGED
|
@@ -29,33 +29,6 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
29
29
|
return getter;
|
|
30
30
|
};
|
|
31
31
|
})();
|
|
32
|
-
(()=>{
|
|
33
|
-
var getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__;
|
|
34
|
-
var leafPrototypes;
|
|
35
|
-
__webpack_require__.t = function(value, mode) {
|
|
36
|
-
if (1 & mode) value = this(value);
|
|
37
|
-
if (8 & mode) return value;
|
|
38
|
-
if ('object' == typeof value && value) {
|
|
39
|
-
if (4 & mode && value.__esModule) return value;
|
|
40
|
-
if (16 & mode && 'function' == typeof value.then) return value;
|
|
41
|
-
}
|
|
42
|
-
var ns = Object.create(null);
|
|
43
|
-
__webpack_require__.r(ns);
|
|
44
|
-
var def = {};
|
|
45
|
-
leafPrototypes = leafPrototypes || [
|
|
46
|
-
null,
|
|
47
|
-
getProto({}),
|
|
48
|
-
getProto([]),
|
|
49
|
-
getProto(getProto)
|
|
50
|
-
];
|
|
51
|
-
for(var current = 2 & mode && value; ('object' == typeof current || 'function' == typeof current) && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{
|
|
52
|
-
def[key] = ()=>value[key];
|
|
53
|
-
});
|
|
54
|
-
def['default'] = ()=>value;
|
|
55
|
-
__webpack_require__.d(ns, def);
|
|
56
|
-
return ns;
|
|
57
|
-
};
|
|
58
|
-
})();
|
|
59
32
|
(()=>{
|
|
60
33
|
__webpack_require__.d = (exports, definition)=>{
|
|
61
34
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|