aberlaas-test 2.22.2 → 2.23.0
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/configs/setupFiles/describeName.js +34 -0
- package/configs/setupFiles/focus.js +3 -0
- package/configs/setupFiles/skip.js +3 -0
- package/configs/setupFiles/slow.js +16 -0
- package/configs/setupFiles/testName.js +3 -6
- package/configs/slow.js +9 -0
- package/configs/vite.js +12 -3
- package/lib/main.js +11 -4
- package/package.json +3 -3
- package/configs/setupFiles/fit-xit-fdescribe-xdescribe.js +0 -13
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make describeName available as a variable in the describe() body.
|
|
3
|
+
*
|
|
4
|
+
* Note: We need to replace the initial describe with a wrapped version that
|
|
5
|
+
* sets describeName when the callback is being executed. We need to be careful
|
|
6
|
+
* to correctly keep all the inner methods as well (like .only, .concurrent,
|
|
7
|
+
* etc).
|
|
8
|
+
**/
|
|
9
|
+
/* global beforeEach, expect */
|
|
10
|
+
|
|
11
|
+
// Keep reference to original method
|
|
12
|
+
const originalDescribe = globalThis.describe;
|
|
13
|
+
|
|
14
|
+
// New wrapping method, that sets describeName when the callback is executed
|
|
15
|
+
const wrappedDescribe = function (name, callback) {
|
|
16
|
+
originalDescribe(name, () => {
|
|
17
|
+
globalThis.describeName = name;
|
|
18
|
+
callback();
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Re-assign the method, but keep internal methods
|
|
23
|
+
globalThis.describe = Object.defineProperties(
|
|
24
|
+
wrappedDescribe,
|
|
25
|
+
Object.getOwnPropertyDescriptors(originalDescribe),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// Make describeName available in all it() callbacks
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
globalThis.describeName = expect
|
|
31
|
+
.getState()
|
|
32
|
+
.currentTestName.split(' > ')
|
|
33
|
+
.at(-2);
|
|
34
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Add .slow() method to it/test/describe for tests that need more time
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
import { slowPrefix, slowTimeout } from '../../configs/slow.js';
|
|
4
|
+
|
|
5
|
+
// Wrapper for it.slow()
|
|
6
|
+
globalThis.it.slow = (name, callback, timeout = slowTimeout) => {
|
|
7
|
+
return globalThis.it(`${slowPrefix} ${name}`, callback, timeout);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// Wrapper for describe.slow()
|
|
11
|
+
globalThis.describe.slow = (name, callback) => {
|
|
12
|
+
return globalThis.describe(`${slowPrefix} ${name}`, () => {
|
|
13
|
+
vi.setConfig({ testTimeout: slowTimeout });
|
|
14
|
+
callback();
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/* global beforeEach, expect */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* test
|
|
5
|
-
*/
|
|
2
|
+
|
|
3
|
+
// Make testName available in all it() callbacks
|
|
6
4
|
beforeEach(() => {
|
|
7
|
-
|
|
8
|
-
globalThis.testName = fullName.split(' > ').pop();
|
|
5
|
+
globalThis.testName = expect.getState().currentTestName.split(' > ').at(-1);
|
|
9
6
|
});
|
package/configs/slow.js
ADDED
package/configs/vite.js
CHANGED
|
@@ -14,21 +14,30 @@ export default defineConfig({
|
|
|
14
14
|
// Hide skipped tests, allowing less noisy debug with fit/fdescribe
|
|
15
15
|
hideSkippedTests: true,
|
|
16
16
|
|
|
17
|
+
// Display details of tests as they run
|
|
18
|
+
reporters: ['tree'],
|
|
19
|
+
|
|
17
20
|
// Tests should be in a __tests__ folder next to their code
|
|
18
21
|
include: ['**/__tests__/**/*.js?(x)'],
|
|
19
22
|
// We ignore temporary folders from the tests
|
|
20
23
|
exclude: aberlaasVitestExclude,
|
|
21
|
-
|
|
24
|
+
|
|
25
|
+
// Restore mocks to their real implementation between tests
|
|
22
26
|
restoreMocks: true,
|
|
27
|
+
// Clear the number of time a mock has been called between tests
|
|
28
|
+
clearMocks: true,
|
|
23
29
|
|
|
24
30
|
// Make describe, it, beforeEach and other globally available
|
|
25
31
|
globals: true,
|
|
26
32
|
// Run before each test file
|
|
27
33
|
setupFiles: [
|
|
28
|
-
`${configDir}/setupFiles/dedent.js`,
|
|
29
34
|
`${configDir}/setupFiles/captureOutput.js`,
|
|
30
|
-
`${configDir}/setupFiles/
|
|
35
|
+
`${configDir}/setupFiles/dedent.js`,
|
|
36
|
+
`${configDir}/setupFiles/describeName.js`,
|
|
37
|
+
`${configDir}/setupFiles/focus.js`,
|
|
31
38
|
`${configDir}/setupFiles/jest-extended.js`,
|
|
39
|
+
`${configDir}/setupFiles/skip.js`,
|
|
40
|
+
`${configDir}/setupFiles/slow.js`,
|
|
32
41
|
`${configDir}/setupFiles/testName.js`,
|
|
33
42
|
],
|
|
34
43
|
},
|
package/lib/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import { _ } from 'golgoth';
|
|
|
2
2
|
import { firostError } from 'firost';
|
|
3
3
|
import { getConfig, hostPackageRoot } from 'aberlaas-helper';
|
|
4
4
|
import { createVitest, registerConsoleShortcuts } from 'vitest/node';
|
|
5
|
+
import { slowPrefix } from '../configs/slow.js';
|
|
5
6
|
import viteConfig from '../configs/vite.js';
|
|
6
7
|
|
|
7
8
|
export let __;
|
|
@@ -13,7 +14,8 @@ export let __;
|
|
|
13
14
|
* $ aberlaas test ./path/to/__tests__/file.js # Test specific files
|
|
14
15
|
* $ aberlaas test ./path/to/file.js # Test specific files
|
|
15
16
|
* $ aberlaas test --related # Test all related files
|
|
16
|
-
* $ aberlaas test --
|
|
17
|
+
* $ aberlaas test --fail-fast # Stop early as soon as one test fails
|
|
18
|
+
* $ aberlaas test --only-slow # Run only tests marked with .slow()
|
|
17
19
|
* $ aberlaas test --flags # Flags passed to vitest
|
|
18
20
|
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
19
21
|
* @returns {boolean} true on success
|
|
@@ -80,9 +82,10 @@ __ = {
|
|
|
80
82
|
const specialMeaningCliArgs = [
|
|
81
83
|
'_',
|
|
82
84
|
'config',
|
|
83
|
-
'
|
|
85
|
+
'fail-fast',
|
|
84
86
|
'related',
|
|
85
87
|
'exclude',
|
|
88
|
+
'only-slow',
|
|
86
89
|
];
|
|
87
90
|
|
|
88
91
|
// Reading base options from the config file
|
|
@@ -99,10 +102,14 @@ __ = {
|
|
|
99
102
|
// by the lint command instead
|
|
100
103
|
allowOnly: true,
|
|
101
104
|
};
|
|
102
|
-
// --
|
|
103
|
-
if (cliArgs
|
|
105
|
+
// --fail-fast stops early as soon as one test fails
|
|
106
|
+
if (cliArgs['fail-fast']) {
|
|
104
107
|
optionsFromAberlaas.bail = 1;
|
|
105
108
|
}
|
|
109
|
+
// --only-slow runs only tests marked with .slow()
|
|
110
|
+
if (cliArgs['only-slow']) {
|
|
111
|
+
optionsFromAberlaas.testNamePattern = _.escapeRegExp(slowPrefix);
|
|
112
|
+
}
|
|
106
113
|
// --related runs also related files
|
|
107
114
|
// Note (2024-10-01): The related option is not documented, but should
|
|
108
115
|
// contain the list of files.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberlaas-test",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.23.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "aberlaas test command: Run automated tests",
|
|
6
6
|
"author": "Tim Carry <tim@pixelastic.com>",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"main": "./lib/main.js",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"aberlaas-helper": "2.
|
|
24
|
+
"aberlaas-helper": "2.23.0",
|
|
25
25
|
"dedent": "1.7.1",
|
|
26
26
|
"firost": "5.5.1",
|
|
27
27
|
"globals": "17.2.0",
|
|
28
28
|
"golgoth": "3.1.0",
|
|
29
29
|
"jest-extended": "4.0.2",
|
|
30
|
-
"vitest": "
|
|
30
|
+
"vitest": "4.0.18"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "cd ../docs && yarn run build",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Add faster to type aliases:
|
|
3
|
-
* - fit, ftest, fdescribe: To focus specific tests
|
|
4
|
-
* - xit, xtest, xdescribe: To skip specific tests
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
globalThis.fit = globalThis.it.only;
|
|
8
|
-
globalThis.ftest = globalThis.test.only;
|
|
9
|
-
globalThis.fdescribe = globalThis.describe.only;
|
|
10
|
-
|
|
11
|
-
globalThis.xit = globalThis.it.skip;
|
|
12
|
-
globalThis.xtest = globalThis.test.skip;
|
|
13
|
-
globalThis.xdescribe = globalThis.describe.skip;
|