sxy-test-runner 0.1.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/dist/config.d.ts +6 -0
- package/dist/config.js +6 -0
- package/dist/describe.d.ts +12 -0
- package/dist/describe.js +21 -0
- package/dist/describe.unitTest.d.ts +1 -0
- package/dist/describe.unitTest.js +25 -0
- package/dist/exported.eslintrc.cjs +9 -0
- package/dist/exported.eslintrc.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/indexNumberToLetters.d.ts +1 -0
- package/dist/indexNumberToLetters.js +10 -0
- package/dist/load.d.ts +1 -0
- package/dist/load.js +3 -0
- package/dist/output.d.ts +5 -0
- package/dist/output.js +26 -0
- package/dist/testsState.d.ts +1 -0
- package/dist/testsState.js +5 -0
- package/dist/timeProfiling.d.ts +2 -0
- package/dist/timeProfiling.js +13 -0
- package/package.json +91 -0
- package/readme.md +206 -0
- package/sxy-loader.config.js +10 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const packageName = "sxy-test-runner";
|
|
2
|
+
export declare const cliName = "sxy-test";
|
|
3
|
+
export declare const configFileName = "sxy-test-runner.config";
|
|
4
|
+
export declare const configLocations: string[];
|
|
5
|
+
export declare const debugging = false;
|
|
6
|
+
export declare const showTimeProfiling = false;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const packageName = 'sxy-test-runner';
|
|
2
|
+
export const cliName = 'sxy-test';
|
|
3
|
+
export const configFileName = 'sxy-test-runner.config';
|
|
4
|
+
export const configLocations = ['', 'config']; // locations where the configs may be placed in proj folder
|
|
5
|
+
export const debugging = false;
|
|
6
|
+
export const showTimeProfiling = false;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
var __sxy_test_runner__: unknown;
|
|
3
|
+
}
|
|
4
|
+
type ShouldCallback = () => void;
|
|
5
|
+
type It = (should: string, shouldCallback: ShouldCallback) => void;
|
|
6
|
+
type TestsCallbackPackage = {
|
|
7
|
+
it: It;
|
|
8
|
+
test: It;
|
|
9
|
+
};
|
|
10
|
+
type TestsCallback = (package: TestsCallbackPackage) => void;
|
|
11
|
+
export declare function describe(theThing: string, testsCallback: TestsCallback): void;
|
|
12
|
+
export {};
|
package/dist/describe.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import chalk from 'chalk-extensions';
|
|
2
|
+
import { debug } from './output.js';
|
|
3
|
+
import { showTimeProfiling } from './config.js';
|
|
4
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
5
|
+
//console.log('sxyDevTools', sxyDevTools)
|
|
6
|
+
//console.log('createTimeProfiler', createTimeProfiler)
|
|
7
|
+
const { timeProfile, timeProfileAsync } = createTimeProfiler(showTimeProfiling);
|
|
8
|
+
export function describe(theThing, testsCallback) {
|
|
9
|
+
//const thisDescribeCounter = global.testState.describeCounter++ // ++: assign the value, THEN increment
|
|
10
|
+
const thisDescribeCounter = global.__sxy_test_runner__.describeCounter;
|
|
11
|
+
global.__sxy_test_runner__.describeCounter++;
|
|
12
|
+
const describe = {
|
|
13
|
+
counter: thisDescribeCounter,
|
|
14
|
+
thing: theThing,
|
|
15
|
+
tests
|
|
16
|
+
};
|
|
17
|
+
//global.testState.describes.push( describe )
|
|
18
|
+
global.__sxy_test_runner__.describes.push(describe);
|
|
19
|
+
debug(chalk.lightgrey `${thisDescribeCounter})`
|
|
20
|
+
+ chalk.lightgrey ` Done with ` + chalk.brightblue `${theThing}\n`);
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { describe } from './describe.js';
|
|
3
|
+
//import { createLoad } from 'sxy-loader'
|
|
4
|
+
//const load = createLoad(import.meta.url)
|
|
5
|
+
mochaDescribe('new describe() function', function () {
|
|
6
|
+
mochaIt('should run tests and output results', async function () {
|
|
7
|
+
this.timeout(6000);
|
|
8
|
+
// eslint-disable-next-line camelcase
|
|
9
|
+
global.__sxy_test_runner__ = {
|
|
10
|
+
describes: [],
|
|
11
|
+
describeCounter: 1
|
|
12
|
+
};
|
|
13
|
+
describe('a thing', ({ it }) => {
|
|
14
|
+
it('should be great', () => {
|
|
15
|
+
expect('it').to.be.great;
|
|
16
|
+
});
|
|
17
|
+
it('should be awesome', () => {
|
|
18
|
+
expect('it').to.be.awesome;
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
global.__sxy_test_runner__.describes.length.should.equal(1);
|
|
22
|
+
global.__sxy_test_runner__.describes[0].thing.should.equal('a thing');
|
|
23
|
+
global.__sxy_test_runner__.describes[0].tests.should.be.a('function');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { describe } from './describe.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { describe } from './describe.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const indexNumberToLetters: any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const indexNumberToLetters = sync(function indexNumberToLetters(number, uppercase = false) {
|
|
2
|
+
const charCodeStart = (uppercase) ? 65 : 97;
|
|
3
|
+
var text = '', letterIndex;
|
|
4
|
+
while (number > 0) {
|
|
5
|
+
letterIndex = (number - 1) % 26;
|
|
6
|
+
text = String.fromCharCode(charCodeStart + letterIndex) + text;
|
|
7
|
+
number = (number - letterIndex) / 26 | 0;
|
|
8
|
+
}
|
|
9
|
+
return text || undefined;
|
|
10
|
+
});
|
package/dist/load.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/load.js
ADDED
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function out(...texts: any[]): void;
|
|
2
|
+
export declare function warn(...texts: any[]): void;
|
|
3
|
+
export declare function error(...texts: any[]): void;
|
|
4
|
+
export declare function log(...texts: any[]): void;
|
|
5
|
+
export declare const debug: (...texts: any[]) => void;
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { debugging } from './config.js';
|
|
3
|
+
function waitToOutput() {
|
|
4
|
+
}
|
|
5
|
+
export function out(...texts) {
|
|
6
|
+
waitToOutput();
|
|
7
|
+
console.log(...texts);
|
|
8
|
+
}
|
|
9
|
+
export function warn(...texts) {
|
|
10
|
+
waitToOutput();
|
|
11
|
+
console.log(...texts);
|
|
12
|
+
}
|
|
13
|
+
export function error(...texts) {
|
|
14
|
+
waitToOutput();
|
|
15
|
+
console.log(...texts);
|
|
16
|
+
}
|
|
17
|
+
export function log(...texts) {
|
|
18
|
+
waitToOutput();
|
|
19
|
+
console.log(...texts);
|
|
20
|
+
}
|
|
21
|
+
export const debug = (debugging)
|
|
22
|
+
? function debug(...texts) {
|
|
23
|
+
waitToOutput();
|
|
24
|
+
console.log(...texts);
|
|
25
|
+
}
|
|
26
|
+
: function () { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const testsState: {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import chalk from 'chalk-extensions';
|
|
2
|
+
import { packageName, showTimeProfiling } from './config.js';
|
|
3
|
+
import { out } from './output.js';
|
|
4
|
+
export const timeProfilingOut = (showTimeProfiling)
|
|
5
|
+
? function timeProfilingOut(name, start, finish) {
|
|
6
|
+
out(chalk.yellow(`[${packageName}] {${name}} time ${finish - start}ms`));
|
|
7
|
+
}
|
|
8
|
+
: function () { };
|
|
9
|
+
export const timeProfilingOutSpecial = (showTimeProfiling)
|
|
10
|
+
? function timeProfilingOutSpecial(name, start, finish) {
|
|
11
|
+
out(chalk.orange(`[${packageName}] {${name}} time ${finish - start}ms`));
|
|
12
|
+
}
|
|
13
|
+
: function () { };
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sxy-test-runner",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"homepage": "https://github.com/RobertSandiford/sxy-test-runner",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/RobertSandiford/sxy-test-runner"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"ES Modules",
|
|
12
|
+
"ES6 Modules",
|
|
13
|
+
"Test Runner",
|
|
14
|
+
"Test Framework",
|
|
15
|
+
"Testing",
|
|
16
|
+
"Unit Testing",
|
|
17
|
+
"Automated Tests"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"module": "dist/index.js",
|
|
22
|
+
"bin": {
|
|
23
|
+
"sxy-test": "./dist/cli/index.js",
|
|
24
|
+
"sxy-test-runner": "./dist/cli/index.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"sxy-loader.config.js",
|
|
29
|
+
"readme.md"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc --watch",
|
|
33
|
+
"dev": "cross-env NODE_OPTIONS=\"--experimental-specifier-resolution=node\" nodemon --experimental-specifier-resolution=node --watch dist/cli --watch dist/cli/lib --watch sxy-test-runner.config.js --watch sxy-loader.config.js dist/cli/index.js",
|
|
34
|
+
"dev-once": "nodemon --experimental-specifier-resolution=node --watch dist/cli --watch sxy-test-runner.config.js --watch sxy-loader.config.js dist/cli/index.js once",
|
|
35
|
+
"dev-init": "node --experimental-specifier-resolution=node dist/cli/index.js init",
|
|
36
|
+
"unit-test": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/*.unitTest.js",
|
|
37
|
+
"unit-test-show-test-result": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/showTestResult.unitTest.js",
|
|
38
|
+
"unit-test-load-config": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/loadConfig.unitTest.js",
|
|
39
|
+
"unit-test-watch-files": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/watchFiles.unitTest.js",
|
|
40
|
+
"unit-test-watch-files-chokidar": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/watchFilesChokidar.unitTest.js",
|
|
41
|
+
"unit-test-watch-files-and-run-tests": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/watchFilesAndRunTests.unitTest.js",
|
|
42
|
+
"unit-test-watch-files-and-run-tests-chokidar": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/watchFilesAndRunTestsChokidar.unitTest.js",
|
|
43
|
+
"unit-test-watch": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/watch.unitTest.js",
|
|
44
|
+
"unit-test-inject-properties": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/injectProperties.unitTest.js",
|
|
45
|
+
"unit-test-run-it": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/runIt.unitTest.js",
|
|
46
|
+
"unit-test-run-describe": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/runDescribe.unitTest.js",
|
|
47
|
+
"unit-test-parse-describe": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/parseDescribe.unitTest.js",
|
|
48
|
+
"unit-test-run-describe-run": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/runDescribeRun.unitTest.js",
|
|
49
|
+
"unit-test-run-test": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/runTest.unitTest.js",
|
|
50
|
+
"unit-test-load-test-file": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/loadTestFile.unitTest.js",
|
|
51
|
+
"unit-test-add-exports": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/addExports.unitTest.js",
|
|
52
|
+
"unit-test-describe": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/describe.unitTest.js",
|
|
53
|
+
"unit-test-run-tests": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/runTests.unitTest.js",
|
|
54
|
+
"mocha-trial": "mocha --watch --parallel --config unitTesting/.mocharc.cjs --watch-files dist,unitTesting dist/**/runTest.unitTest.js"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@babel/core": "^7.22.11",
|
|
58
|
+
"chalk-extensions": "^2.0.9",
|
|
59
|
+
"chokidar": "^3.5.3",
|
|
60
|
+
"cross-env": "^7.0.3",
|
|
61
|
+
"dependency-tree": "^8.1.2",
|
|
62
|
+
"figures": "^4.0.1",
|
|
63
|
+
"glob": "^7.2.3",
|
|
64
|
+
"globby": "^12.2.0",
|
|
65
|
+
"minimatch": "^5.1.6",
|
|
66
|
+
"node-watch": "^0.7.4",
|
|
67
|
+
"slash": "^5.1.0",
|
|
68
|
+
"sxy-dev-tools": "^1.0.6",
|
|
69
|
+
"sxy-helpers": "^1.0.0",
|
|
70
|
+
"sxy-lib": "^1.0.12",
|
|
71
|
+
"sxy-lib-object-copy": "^1.0.5",
|
|
72
|
+
"sxy-loader": "^2.1.0",
|
|
73
|
+
"sxy-standard": "^1.0.12",
|
|
74
|
+
"sxy-standard-object-copy": "^1.0.5"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@babel/cli": "^7.22.10",
|
|
78
|
+
"@types/node": "^20.5.7",
|
|
79
|
+
"babel-plugin-transform-awaitful": "^1.0.0",
|
|
80
|
+
"chai": "^4.3.8",
|
|
81
|
+
"chai-as-promised": "^7.1.1",
|
|
82
|
+
"eslint": "^7.32.0",
|
|
83
|
+
"eslint-config-sandi": "^1.2.0",
|
|
84
|
+
"mocha": "^9.2.2",
|
|
85
|
+
"mocha-steps": "^1.3.0",
|
|
86
|
+
"nodemon": "^2.0.22",
|
|
87
|
+
"sinon": "^12.0.1",
|
|
88
|
+
"sinon-chai": "^3.7.0",
|
|
89
|
+
"typescript": "^5.2.2"
|
|
90
|
+
}
|
|
91
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# sxy-test-runner
|
|
2
|
+
|
|
3
|
+
Mocha-like test runner for **es modules** (only), with **watch mode**, and **re-running only tests related to changes** (by dependency analysis), full **async code support**
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { describe } from 'sxy-test-runner'
|
|
7
|
+
import { should as setupShould } from 'chai'
|
|
8
|
+
const should = setupShould()
|
|
9
|
+
|
|
10
|
+
function add(a, b) {
|
|
11
|
+
return a + b
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('The add() function', ({it}) => {
|
|
15
|
+
it('should add 1 and 2, making 3', () => {
|
|
16
|
+
const result = add(1, 2)
|
|
17
|
+
result.should.equal(3)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### 1. Install
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npm i -D sxy-test-runner
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
*or*
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
yarn add -D sxy-test-runner
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
*or*
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
pnpm add -D sxy-test-runner
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### 2. Create a config (required)
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
sxy-test-runner init
|
|
48
|
+
```
|
|
49
|
+
*sxy-test is an alias for sxy-test-runner and can be used instead*
|
|
50
|
+
|
|
51
|
+
This will create a config in your project folder. It can be moved to a folder named "config" if you prefer, or specify a location using --config
|
|
52
|
+
|
|
53
|
+
### 3. Modify the config, specifying the base path for tests and code to watch, and glob patterns for tests and code to watch
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
{
|
|
57
|
+
// base folder for tests matching and ignore patterns
|
|
58
|
+
testsBase: 'dist',
|
|
59
|
+
|
|
60
|
+
// glob pattern or array of glob patterns of test files
|
|
61
|
+
tests: [
|
|
62
|
+
'**/*.test.{js,jsx}'
|
|
63
|
+
],
|
|
64
|
+
|
|
65
|
+
// watch mode configurations
|
|
66
|
+
watch: {
|
|
67
|
+
|
|
68
|
+
//// the base directory to watch files in
|
|
69
|
+
watchFilesBase: 'dist',
|
|
70
|
+
|
|
71
|
+
//// glob filter or array of global filters of files to watch
|
|
72
|
+
watchFiles: '**/*.js',
|
|
73
|
+
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The other config options and fairly well explained in the config. More info on them later.
|
|
79
|
+
|
|
80
|
+
### 4. Run
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
npx sxy-test-runner
|
|
84
|
+
```
|
|
85
|
+
*sxy-test is an alias for sxy-test-runner and can be used instead*
|
|
86
|
+
|
|
87
|
+
("npx" can be omitted in package.json scripts)
|
|
88
|
+
|
|
89
|
+
sxy-test-runner runs watch mode, re-running only relevant tests, by default.
|
|
90
|
+
|
|
91
|
+
To run tests only once and not watch (e.g. for ci/cd), use
|
|
92
|
+
```
|
|
93
|
+
npx sxy-test-runner once
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To specific an alternate config, use -c or --config
|
|
97
|
+
```
|
|
98
|
+
npx sxy-test-runner --config sxy-test-runner.alternate.config.js
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
# How it works
|
|
102
|
+
|
|
103
|
+
sxy-test-runner runs all tests inside one node process, to improve performance (this framework far exceeds mocha in parallel mode, which is needed to test ESM files, due to this).
|
|
104
|
+
|
|
105
|
+
Because of this, be careful with globals, which will be shared.
|
|
106
|
+
|
|
107
|
+
## Execution modes
|
|
108
|
+
|
|
109
|
+
**execution** settings let you choose whether to run test files, describe blocks, and individual tests sequentially or in parallel.
|
|
110
|
+
|
|
111
|
+
If working with globals you may want to use sequential only, to avoid conflicts on those globals.
|
|
112
|
+
|
|
113
|
+
Sequential mode also allows console log output to be displayed correctly with each test. Running in parallel mode does not allow log output to be matched up to each test, due to the use of a global override on console.log (other console output methods such as console.trace() are not covered currently)
|
|
114
|
+
|
|
115
|
+
If your code is isolated, and asyncronous, you can use parallel exeecution modes to radically speed up your tests, as the expense of the points mentioned above.
|
|
116
|
+
|
|
117
|
+
## Dependencies
|
|
118
|
+
|
|
119
|
+
Module dependencies are identified using dependency-tree. Dynamic imports will not be detected and will not trigger test re-runs.
|
|
120
|
+
|
|
121
|
+
No option to re-run all tests on changes is currently available - I may add this on request, or submit a PR if you want this.
|
|
122
|
+
|
|
123
|
+
## Failing test re-running
|
|
124
|
+
|
|
125
|
+
Default behaviour is to re-run any failing test any time a change is made, even if that change isn't relevant to the failing test. This is to ensure you can see where attention is needed. Turn this off in the config if it is not convenient for you: config.watch.reRunFailingTests
|
|
126
|
+
|
|
127
|
+
## Reloading modules
|
|
128
|
+
|
|
129
|
+
A key challenge in creating an ESM test runner is re-loading modules due to the engine not letting us clear the import cache of ESM modules. This framework relies on sxy-loader, which uses a babel transform to transform modules into a reloadable format with a controllable cache. A cache of transformed code is kept to keep the process speedy.
|
|
130
|
+
|
|
131
|
+
Performance is a little less than a native module import, but not so much as to be notable inconvenience. Re-running only test related to changes keep performance strong even in very large projects.
|
|
132
|
+
|
|
133
|
+
# Advanced usage
|
|
134
|
+
|
|
135
|
+
## 1. Run tasks at startup - setup
|
|
136
|
+
|
|
137
|
+
Edit config.setup. This config value can take a function, a file to import relative to the project folder, or an array or one or both of those.
|
|
138
|
+
|
|
139
|
+
## 2. Run tasks before each test file / describe / test globally
|
|
140
|
+
|
|
141
|
+
Edit config.beforeEachFile / config.beforeEachDescribe / config.beforeEachTest with a function, file or array of either.
|
|
142
|
+
|
|
143
|
+
If a file exports named values, or a function returns an object with properties, these keys will be added to a storage object (beware of conflicting names). This object is then passed to the afterEachFile / afterEachDescribe / afterEachTest tasks for cleanup.
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
// tasks to run before each test file is run
|
|
147
|
+
beforeEachFile: () => {
|
|
148
|
+
const thing = prepSomething()
|
|
149
|
+
return { thing }
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
// tasks to run after each test file is run
|
|
153
|
+
afterEachFile: ({thing}) => {
|
|
154
|
+
destroyingSomething(thing)
|
|
155
|
+
},
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 3. Run code before each describe block, or at the end of a test file - per test file
|
|
159
|
+
|
|
160
|
+
Not yet implemented.
|
|
161
|
+
|
|
162
|
+
## 4. Run code before each test, after each test, or after the describe block - per describe block
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
import { describe } from 'sxy-test-runner'
|
|
166
|
+
import { should as setupShould } from 'chai'
|
|
167
|
+
const should = setupShould()
|
|
168
|
+
|
|
169
|
+
describe('something', ({it, beforeEachTest, afterEachTest, afterDescribe}) => {
|
|
170
|
+
|
|
171
|
+
// setup can take place here without any special measures
|
|
172
|
+
// but you can only safely set globals for your test here if your
|
|
173
|
+
// execution mode for files and describes is 'sequential' (default)
|
|
174
|
+
const something = createSomething()
|
|
175
|
+
|
|
176
|
+
// run this just before each test
|
|
177
|
+
beforeEachTest(() => {
|
|
178
|
+
prepSomething(something)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
// run this just after each test
|
|
182
|
+
afterEachTest(() => {
|
|
183
|
+
clearupSomething(something)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('should do something', () => {
|
|
187
|
+
something.should.do.something
|
|
188
|
+
})
|
|
189
|
+
it('should do another thing', () => {
|
|
190
|
+
something.should.do.another.thing
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
// teardown should go in afterDescribe.
|
|
194
|
+
// tests are not run syncronously within the describe block (even sync tests)
|
|
195
|
+
// so cleanup code here would run too early
|
|
196
|
+
afterDescribe(() => {
|
|
197
|
+
destroySomething(something)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
# Known issues
|
|
205
|
+
|
|
206
|
+
sxy-loader effectively uses eval to run modules, to get around the ESM limited of being unable to reload modules. This has a harmful effect on error reporting when code hits errors. I have some plans to work on error reporting, or work to get changes made to the ESM spec, but at current time error reporting isn't great.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
export default {
|
|
3
|
+
//returnStyle: 'esm-dynamic', // 'esm-dynamic' | 'esm-static'
|
|
4
|
+
mode: process.env.NODE_ENV, // 'development' | 'production' environment
|
|
5
|
+
//transformCaching: 'content', // content | hash | false // default content
|
|
6
|
+
//transformCacheStorage: 'file', // 'file' | 'memory'
|
|
7
|
+
//transformCacheStorageLocation: '__cache', // null | path/to/location/from/project/dir
|
|
8
|
+
quiet: true, // disable info output
|
|
9
|
+
debug: false, // debugging output // doesn't work yet
|
|
10
|
+
}
|