@git.zone/tstest 5.0.0 → 6.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/.smartconfig.json +5 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/index.d.ts +3 -0
- package/dist_ts/index.js +34 -1
- package/dist_ts/tstest.classes.artifacts.d.ts +32 -0
- package/dist_ts/tstest.classes.artifacts.js +144 -0
- package/dist_ts/tstest.classes.beforescripts.d.ts +3 -1
- package/dist_ts/tstest.classes.beforescripts.js +18 -4
- package/dist_ts/tstest.classes.config.d.ts +11 -0
- package/dist_ts/tstest.classes.config.js +21 -0
- package/dist_ts/tstest.classes.tstest.js +12 -1
- package/dist_ts/tstest.interfaces.config.d.ts +51 -0
- package/dist_ts/tstest.interfaces.config.js +7 -0
- package/dist_ts/tstest.plugins.d.ts +2 -1
- package/dist_ts/tstest.plugins.js +3 -2
- package/dist_ts_tapbundle_serverside/classes.tapnodetools.d.ts +2 -2
- package/dist_ts_tapbundle_serverside/classes.tapnodetools.js +10 -10
- package/dist_ts_tapbundle_serverside/plugins.d.ts +1 -0
- package/dist_ts_tapbundle_serverside/plugins.js +3 -1
- package/package.json +9 -6
- package/readme.md +80 -4
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/index.ts +51 -0
- package/ts/tstest.classes.artifacts.ts +173 -0
- package/ts/tstest.classes.beforescripts.ts +15 -3
- package/ts/tstest.classes.config.ts +25 -0
- package/ts/tstest.classes.tstest.ts +12 -0
- package/ts/tstest.interfaces.config.ts +55 -0
- package/ts/tstest.plugins.ts +2 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as plugins from './tstest.plugins.js';
|
|
2
|
+
import type { ITstestConfig } from './tstest.interfaces.config.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Read the `@git.zone/tstest` section of `.smartconfig.json`, following the
|
|
6
|
+
* same convention as tsbundle, tswatch, tsrust and tsdocker. A project
|
|
7
|
+
* without the section gets the defaults, so this is safe to call anywhere.
|
|
8
|
+
*/
|
|
9
|
+
export const loadTstestConfig = (cwd: string): ITstestConfig => {
|
|
10
|
+
try {
|
|
11
|
+
const smartconfigInstance = new plugins.smartconfig.Smartconfig(cwd);
|
|
12
|
+
return smartconfigInstance.dataFor<ITstestConfig>('@git.zone/tstest', {});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(`tstest: could not read .smartconfig.json (${error}); using defaults`);
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Cleanup runs on release unless the project opts out. */
|
|
20
|
+
export const cleanupRunsOnRelease = (config: ITstestConfig): boolean =>
|
|
21
|
+
config.cleanup?.onRelease !== false;
|
|
22
|
+
|
|
23
|
+
/** Cleanup after a local test run is opt-in. */
|
|
24
|
+
export const cleanupRunsAfterTests = (config: ITstestConfig): boolean =>
|
|
25
|
+
config.cleanup?.afterRun === true;
|
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
|
|
30
30
|
// Before-script support
|
|
31
31
|
import { loadBeforeScripts, runBeforeScript, type IBeforeScripts } from './tstest.classes.beforescripts.js';
|
|
32
|
+
import { cleanupRunsAfterTests, loadTstestConfig } from './tstest.classes.config.js';
|
|
33
|
+
import { cleanArtifacts, formatBytes } from './tstest.classes.artifacts.js';
|
|
32
34
|
|
|
33
35
|
export class TsTest {
|
|
34
36
|
public testDir: TestDirectory;
|
|
@@ -164,6 +166,16 @@ export class TsTest {
|
|
|
164
166
|
*/
|
|
165
167
|
public async cleanup() {
|
|
166
168
|
this.smartshellInstance.smartexit.deregister();
|
|
169
|
+
|
|
170
|
+
// Opt-in: projects that do not want their test output kept can have it
|
|
171
|
+
// removed as soon as the run finishes.
|
|
172
|
+
const config = loadTstestConfig(this.testDir.cwd);
|
|
173
|
+
if (cleanupRunsAfterTests(config)) {
|
|
174
|
+
const result = cleanArtifacts(this.testDir.cwd, config);
|
|
175
|
+
if (result.totalBytes > 0) {
|
|
176
|
+
console.log(`tstest: cleaned test artifacts, reclaimed ${formatBytes(result.totalBytes)}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
public async runWatch(ignorePatterns: string[] = []) {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project configuration for tstest, read from the `@git.zone/tstest` section
|
|
3
|
+
* of `.smartconfig.json` - the same mechanism tsbundle, tswatch, tsrust and
|
|
4
|
+
* tsdocker already use.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The artifact groups tstest writes to disk. Each maps to a fixed path under
|
|
9
|
+
* `.nogit/`; see `artifactPaths` in tstest.classes.artifacts.ts.
|
|
10
|
+
*/
|
|
11
|
+
export type TTstestArtifact = 'logs' | 'cache' | 'testfiles' | 'snapshots';
|
|
12
|
+
|
|
13
|
+
export interface ITstestPrepareConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Command run once, before the whole test run. Takes precedence over the
|
|
16
|
+
* `test:before` / `test:before:once` package.json scripts.
|
|
17
|
+
*/
|
|
18
|
+
once?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Command run before every individual test file. Takes precedence over the
|
|
21
|
+
* `test:before:testfile` package.json script.
|
|
22
|
+
*/
|
|
23
|
+
perTestfile?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ITstestCleanupConfig {
|
|
27
|
+
/**
|
|
28
|
+
* Remove test artifacts as part of `gitzone release`. Defaults to true, so
|
|
29
|
+
* a release never ships with stale test output left on disk. Set false to
|
|
30
|
+
* opt a project out.
|
|
31
|
+
*/
|
|
32
|
+
onRelease?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Also remove artifacts after every local test run. Defaults to false,
|
|
35
|
+
* because the logs are usually the reason someone ran the tests.
|
|
36
|
+
*/
|
|
37
|
+
afterRun?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Artifact groups to remove. Defaults to logs, cache and testfiles.
|
|
40
|
+
* `snapshots` is deliberately not a default: snapshots are assertion
|
|
41
|
+
* baselines, and deleting them makes `matchSnapshot` silently re-record
|
|
42
|
+
* rather than compare.
|
|
43
|
+
*/
|
|
44
|
+
artifacts?: TTstestArtifact[];
|
|
45
|
+
/**
|
|
46
|
+
* Additional project-specific paths to remove, relative to the project
|
|
47
|
+
* root. Absolute paths and paths escaping the project root are rejected.
|
|
48
|
+
*/
|
|
49
|
+
additionalPaths?: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ITstestConfig {
|
|
53
|
+
prepare?: ITstestPrepareConfig;
|
|
54
|
+
cleanup?: ITstestCleanupConfig;
|
|
55
|
+
}
|
package/ts/tstest.plugins.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { fs, path, url };
|
|
|
8
8
|
// @push.rocks scope
|
|
9
9
|
import * as consolecolor from '@push.rocks/consolecolor';
|
|
10
10
|
import * as smartbrowser from '@push.rocks/smartbrowser';
|
|
11
|
+
import * as smartconfig from '@push.rocks/smartconfig';
|
|
11
12
|
import * as smartserve from '@push.rocks/smartserve';
|
|
12
13
|
import * as smartdelay from '@push.rocks/smartdelay';
|
|
13
14
|
import * as smartfile from '@push.rocks/smartfile';
|
|
@@ -23,6 +24,7 @@ import * as tapbundle from '../dist_ts_tapbundle/index.js';
|
|
|
23
24
|
export {
|
|
24
25
|
consolecolor,
|
|
25
26
|
smartbrowser,
|
|
27
|
+
smartconfig,
|
|
26
28
|
smartserve,
|
|
27
29
|
smartdelay,
|
|
28
30
|
smartfile,
|