aberlaas-test 2.23.0 → 2.24.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/configs/setupFiles/bench.js +5 -0
- package/configs/setupFiles/matchers.js +43 -0
- package/configs/setupFiles/mockStdin.js +37 -0
- package/configs/setupFiles/slow.js +2 -2
- package/configs/slow.js +1 -1
- package/configs/vite.js +4 -2
- package/lib/main.js +0 -1
- package/package.json +3 -4
- package/configs/setupFiles/jest-extended.js +0 -10
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Helpful matchers not included in Vitest
|
|
2
|
+
import { _ } from 'golgoth';
|
|
3
|
+
import { expect } from 'vitest';
|
|
4
|
+
|
|
5
|
+
expect.extend({
|
|
6
|
+
toInclude(received, expected) {
|
|
7
|
+
return {
|
|
8
|
+
pass: _.includes(received, expected),
|
|
9
|
+
message: () =>
|
|
10
|
+
this.isNot
|
|
11
|
+
? `expected not to include ${expected}`
|
|
12
|
+
: `expected to include ${expected}`,
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
toBeString(received) {
|
|
17
|
+
return {
|
|
18
|
+
pass: _.isString(received),
|
|
19
|
+
message: () =>
|
|
20
|
+
this.isNot ? 'expected not to be a string' : 'expected to be a string',
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
toStartWith(received, expected) {
|
|
25
|
+
return {
|
|
26
|
+
pass: _.startsWith(received, expected),
|
|
27
|
+
message: () =>
|
|
28
|
+
this.isNot
|
|
29
|
+
? `expected not to start with ${expected}`
|
|
30
|
+
: `expected to start with ${expected}`,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
toEndWith(received, expected) {
|
|
35
|
+
return {
|
|
36
|
+
pass: _.endsWith(received, expected),
|
|
37
|
+
message: () =>
|
|
38
|
+
this.isNot
|
|
39
|
+
? `expected not to end with ${expected}`
|
|
40
|
+
: `expected to end with ${expected}`,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PassThrough } from 'node:stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Allow mocking stdin in tests.
|
|
5
|
+
* Usage:
|
|
6
|
+
* mockStdin((stdin) => {
|
|
7
|
+
* // do something
|
|
8
|
+
* stdin.push('abc');
|
|
9
|
+
* });
|
|
10
|
+
* Initial code inspired by: https://github.com/sindresorhus/ora/blob/main/test.js
|
|
11
|
+
* @param {Function} callback Method called with a fake stdin as first argument
|
|
12
|
+
* @returns {any} Return value of the callback
|
|
13
|
+
**/
|
|
14
|
+
globalThis.mockStdin = function (callback) {
|
|
15
|
+
const originalStdinDescriptor = Object.getOwnPropertyDescriptor(
|
|
16
|
+
process,
|
|
17
|
+
'stdin',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const fakeStdin = new PassThrough();
|
|
21
|
+
fakeStdin.isTTY = true;
|
|
22
|
+
fakeStdin.isRaw = false;
|
|
23
|
+
fakeStdin.setRawMode = (value) => {
|
|
24
|
+
fakeStdin.isRaw = value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
Object.defineProperty(process, 'stdin', {
|
|
28
|
+
value: fakeStdin,
|
|
29
|
+
configurable: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
return callback(fakeStdin);
|
|
34
|
+
} finally {
|
|
35
|
+
Object.defineProperty(process, 'stdin', originalStdinDescriptor);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -4,12 +4,12 @@ import { slowPrefix, slowTimeout } from '../../configs/slow.js';
|
|
|
4
4
|
|
|
5
5
|
// Wrapper for it.slow()
|
|
6
6
|
globalThis.it.slow = (name, callback, timeout = slowTimeout) => {
|
|
7
|
-
return globalThis.it(`${slowPrefix}
|
|
7
|
+
return globalThis.it(`${slowPrefix}${name}`, callback, timeout);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
// Wrapper for describe.slow()
|
|
11
11
|
globalThis.describe.slow = (name, callback) => {
|
|
12
|
-
return globalThis.describe(`${slowPrefix}
|
|
12
|
+
return globalThis.describe(`${slowPrefix}${name}`, () => {
|
|
13
13
|
vi.setConfig({ testTimeout: slowTimeout });
|
|
14
14
|
callback();
|
|
15
15
|
});
|
package/configs/slow.js
CHANGED
package/configs/vite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dirname } from 'firost';
|
|
2
2
|
import { defaultExclude, defineConfig } from 'vitest/config';
|
|
3
3
|
|
|
4
|
-
const aberlaasVitestExclude = [...defaultExclude, '**/tmp/**'];
|
|
4
|
+
const aberlaasVitestExclude = [...defaultExclude, '**/tmp/**', '**/*.bench.js'];
|
|
5
5
|
|
|
6
6
|
const configDir = dirname();
|
|
7
7
|
|
|
@@ -31,11 +31,13 @@ export default defineConfig({
|
|
|
31
31
|
globals: true,
|
|
32
32
|
// Run before each test file
|
|
33
33
|
setupFiles: [
|
|
34
|
+
`${configDir}/setupFiles/bench.js`,
|
|
34
35
|
`${configDir}/setupFiles/captureOutput.js`,
|
|
35
36
|
`${configDir}/setupFiles/dedent.js`,
|
|
36
37
|
`${configDir}/setupFiles/describeName.js`,
|
|
37
38
|
`${configDir}/setupFiles/focus.js`,
|
|
38
|
-
`${configDir}/setupFiles/
|
|
39
|
+
`${configDir}/setupFiles/matchers.js`,
|
|
40
|
+
`${configDir}/setupFiles/mockStdin.js`,
|
|
39
41
|
`${configDir}/setupFiles/skip.js`,
|
|
40
42
|
`${configDir}/setupFiles/slow.js`,
|
|
41
43
|
`${configDir}/setupFiles/testName.js`,
|
package/lib/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberlaas-test",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "aberlaas test command: Run automated tests",
|
|
6
6
|
"author": "Tim Carry <tim@pixelastic.com>",
|
|
@@ -21,12 +21,11 @@
|
|
|
21
21
|
},
|
|
22
22
|
"main": "./lib/main.js",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"aberlaas-helper": "2.
|
|
24
|
+
"aberlaas-helper": "2.24.1",
|
|
25
25
|
"dedent": "1.7.1",
|
|
26
|
-
"firost": "5.
|
|
26
|
+
"firost": "5.6.1",
|
|
27
27
|
"globals": "17.2.0",
|
|
28
28
|
"golgoth": "3.1.0",
|
|
29
|
-
"jest-extended": "4.0.2",
|
|
30
29
|
"vitest": "4.0.18"
|
|
31
30
|
},
|
|
32
31
|
"scripts": {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// We use extended matchers from jest-extended in vitest
|
|
2
|
-
// It includes matcher like .toStartWith, .toBeEmpty, etc
|
|
3
|
-
// See: https://github.com/jest-community/jest-extended
|
|
4
|
-
//
|
|
5
|
-
// The expect.extend() from Vitest is compatible with the one from Jest, so
|
|
6
|
-
// setup is straightforward
|
|
7
|
-
import * as matchers from 'jest-extended';
|
|
8
|
-
import { expect } from 'vitest';
|
|
9
|
-
|
|
10
|
-
expect.extend(matchers);
|