@virmator/plugin-testing 13.3.11 → 13.3.13
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/augments/fs/dir-contents.js +6 -6
- package/dist/test-plugin.d.ts +4 -5
- package/dist/test-plugin.js +15 -25
- package/package.json +8 -7
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { getObjectTypedEntries } from '@augment-vir/common';
|
|
3
|
+
import { writeFileAndDir } from '@augment-vir/node';
|
|
3
4
|
import { readdir, readFile, rm, stat } from 'node:fs/promises';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
|
-
import { isRunTimeType } from 'run-time-assertions';
|
|
6
6
|
/** Read all contents within a directory and store them in an object. Optionally recursive. */
|
|
7
7
|
export async function readAllDirContents(dir, { recursive = false, excludeList, }) {
|
|
8
8
|
const fileNames = (await readdir(dir)).sort();
|
|
9
9
|
const allFileContents = await Promise.all(fileNames.map(async (fileName) => {
|
|
10
10
|
const filePath = join(dir, fileName);
|
|
11
11
|
if (excludeList?.some((excludeItem) => {
|
|
12
|
-
if (
|
|
12
|
+
if (check.isString(excludeItem)) {
|
|
13
13
|
return filePath.includes(excludeItem);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
@@ -24,7 +24,7 @@ export async function readAllDirContents(dir, { recursive = false, excludeList,
|
|
|
24
24
|
: recursive
|
|
25
25
|
? await readAllDirContents(filePath, { recursive, excludeList })
|
|
26
26
|
: undefined;
|
|
27
|
-
if (isObject(contents) && !Object.keys(contents).length) {
|
|
27
|
+
if (check.isObject(contents) && !Object.keys(contents).length) {
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
return contents;
|
|
@@ -49,7 +49,7 @@ export async function resetDirContents(rootDir, contents) {
|
|
|
49
49
|
export async function writeDirContents(rootDir, contents) {
|
|
50
50
|
await Promise.all(getObjectTypedEntries(contents).map(async ([relativePath, content,]) => {
|
|
51
51
|
const fullPath = join(rootDir, relativePath);
|
|
52
|
-
if (
|
|
52
|
+
if (check.isString(content)) {
|
|
53
53
|
await writeFileAndDir(fullPath, content);
|
|
54
54
|
}
|
|
55
55
|
else {
|
package/dist/test-plugin.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { MaybePromise,
|
|
2
|
-
import {
|
|
1
|
+
import { LogOutputType, MaybePromise, PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type UniversalTestContext } from '@augment-vir/test';
|
|
3
3
|
import { VirmatorPlugin } from '@virmator/core';
|
|
4
|
-
import { TestContext } from 'node:test';
|
|
5
4
|
import { DirContents } from './augments/index.js';
|
|
6
5
|
/** Log string transformer. */
|
|
7
6
|
export type LogTransform = (logType: LogOutputType, arg: string) => string;
|
|
@@ -20,7 +19,7 @@ export type TestPluginResult = {
|
|
|
20
19
|
error?: Error;
|
|
21
20
|
};
|
|
22
21
|
/** Optional options for {@link testPlugin}. */
|
|
23
|
-
export type TestPluginOptions =
|
|
22
|
+
export type TestPluginOptions = PartialWithUndefined<{
|
|
24
23
|
/** Transforms the final log string output of a plugin's command. */
|
|
25
24
|
logTransform: LogTransform;
|
|
26
25
|
/** Exclude the given contents from directory reading. */
|
|
@@ -29,4 +28,4 @@ export type TestPluginOptions = PartialAndUndefined<{
|
|
|
29
28
|
beforeCleanupCallback: (cwd: string) => MaybePromise<void>;
|
|
30
29
|
}>;
|
|
31
30
|
/** Tests a virmator plugin and saves a snapshot of the results. */
|
|
32
|
-
export declare function testPlugin(shouldPass: boolean, context:
|
|
31
|
+
export declare function testPlugin(shouldPass: boolean, context: UniversalTestContext, plugin: Readonly<VirmatorPlugin> | ReadonlyArray<Readonly<VirmatorPlugin>>, cliCommand: string, cwd: string, { excludeContents, logTransform, beforeCleanupCallback, }?: TestPluginOptions): Promise<void>;
|
package/dist/test-plugin.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import { addSuffix, getOrSet,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { addSuffix, createLogger, diffObjects, getOrSet, LogOutputType, mapObjectValues, removeColor, RuntimeEnv, wrapInTry, wrapString, } from '@augment-vir/common';
|
|
2
|
+
import { toPosixPath } from '@augment-vir/node';
|
|
3
|
+
import { assertTestContext } from '@augment-vir/test';
|
|
4
|
+
import { executeVirmatorCommand, findClosestPackageDir, hideNoTraceTraces, VirmatorNoTraceError, } from '@virmator/core';
|
|
4
5
|
import { relative, sep } from 'node:path';
|
|
5
|
-
import { diffObjects } from 'run-time-assertions';
|
|
6
6
|
import { readAllDirContents, resetDirContents } from './augments/index.js';
|
|
7
7
|
import { monoRepoDir } from './file-paths.js';
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
.filter(isTruthy);
|
|
14
|
-
}
|
|
15
|
-
function handleWrite(logs, logType, args) {
|
|
16
|
-
const serialized = serializeLogArgs(args);
|
|
17
|
-
if (serialized.length) {
|
|
18
|
-
getOrSet(logs, logType, () => []).push(serialized);
|
|
8
|
+
function handleWrite(logs, logType, text) {
|
|
9
|
+
const fixed = removeColor(text).replaceAll(addSuffix({ value: monoRepoDir, suffix: '/' }), '');
|
|
10
|
+
if (fixed.length) {
|
|
11
|
+
getOrSet(logs, logType, () => []).push(fixed);
|
|
19
12
|
}
|
|
20
13
|
return true;
|
|
21
14
|
}
|
|
@@ -28,19 +21,16 @@ const defaultContentsExcludeList = [
|
|
|
28
21
|
];
|
|
29
22
|
/** Tests a virmator plugin and saves a snapshot of the results. */
|
|
30
23
|
export async function testPlugin(shouldPass, context, plugin, cliCommand, cwd, { excludeContents = [], logTransform = (type, arg) => arg, beforeCleanupCallback, } = {}) {
|
|
24
|
+
assertTestContext(context, RuntimeEnv.Node);
|
|
31
25
|
const logs = {};
|
|
32
|
-
const logger =
|
|
33
|
-
stderr
|
|
34
|
-
|
|
35
|
-
return handleWrite(logs, LogOutputType.error, args);
|
|
36
|
-
},
|
|
26
|
+
const logger = createLogger({
|
|
27
|
+
stderr({ text }) {
|
|
28
|
+
return handleWrite(logs, LogOutputType.Error, text);
|
|
37
29
|
},
|
|
38
|
-
stdout
|
|
39
|
-
|
|
40
|
-
return handleWrite(logs, LogOutputType.standard, args);
|
|
41
|
-
},
|
|
30
|
+
stdout({ text }) {
|
|
31
|
+
return handleWrite(logs, LogOutputType.Standard, text);
|
|
42
32
|
},
|
|
43
|
-
}
|
|
33
|
+
});
|
|
44
34
|
const fullExcludeList = [
|
|
45
35
|
...excludeContents,
|
|
46
36
|
...defaultContentsExcludeList,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virmator/plugin-testing",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.13",
|
|
4
4
|
"description": "Testing for virmator plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"virmator",
|
|
@@ -30,18 +30,19 @@
|
|
|
30
30
|
"test:update": "npm test update"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@augment-vir/
|
|
34
|
-
"@augment-vir/
|
|
35
|
-
"@
|
|
33
|
+
"@augment-vir/assert": "^30.0.4",
|
|
34
|
+
"@augment-vir/common": "^30.0.4",
|
|
35
|
+
"@augment-vir/node": "^30.0.4",
|
|
36
|
+
"@virmator/core": "^13.3.13",
|
|
36
37
|
"cli-args-vir": "^0.0.3",
|
|
37
|
-
"run-time-assertions": "^1.5.2",
|
|
38
38
|
"type-fest": "^4.26.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
41
|
+
"@augment-vir/test": "^30.0.4",
|
|
42
|
+
"@types/node": "^22.5.5",
|
|
42
43
|
"c8": "^10.1.2",
|
|
43
44
|
"istanbul-smart-text-reporter": "^1.1.4",
|
|
44
|
-
"tsx": "^4.19.
|
|
45
|
+
"tsx": "^4.19.1",
|
|
45
46
|
"typescript": "^5.6.2"
|
|
46
47
|
},
|
|
47
48
|
"engines": {
|