flake-monster 0.3.0 → 0.3.2
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import { dirname, join, posix } from 'node:path';
|
|
3
3
|
import { parseSource } from './parser.js';
|
|
4
|
-
import { computeInjections, computeRuntimeImportInsertion, applyInsertions } from './injector.js';
|
|
4
|
+
import { computeInjections, computeRuntimeImportInsertion, applyInsertions, MARKER_PREFIX } from './injector.js';
|
|
5
5
|
import { recoverDelays, scanForRecovery } from './remover.js';
|
|
6
6
|
|
|
7
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -43,18 +43,28 @@ export function createJavaScriptAdapter() {
|
|
|
43
43
|
},
|
|
44
44
|
|
|
45
45
|
inject(source, options) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (runtimeNeeded) {
|
|
51
|
-
const importPath = computeRuntimeImportPath(options.filePath);
|
|
52
|
-
const imp = computeRuntimeImportInsertion(ast, source, importPath);
|
|
53
|
-
if (imp) insertions.push(imp);
|
|
46
|
+
if (source.includes(MARKER_PREFIX)) {
|
|
47
|
+
console.warn(` Skipping ${options.filePath}: already injected (restore first)`);
|
|
48
|
+
return { source, points: [], runtimeNeeded: false };
|
|
54
49
|
}
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
try {
|
|
52
|
+
const { ast } = parseSource(source);
|
|
53
|
+
const { insertions, points } = computeInjections(ast, source, options);
|
|
54
|
+
const runtimeNeeded = points.length > 0;
|
|
55
|
+
|
|
56
|
+
if (runtimeNeeded) {
|
|
57
|
+
const importPath = computeRuntimeImportPath(options.filePath);
|
|
58
|
+
const imp = computeRuntimeImportInsertion(ast, source, importPath);
|
|
59
|
+
if (imp) insertions.push(imp);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const output = applyInsertions(source, insertions);
|
|
63
|
+
return { source: output, points, runtimeNeeded };
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.warn(` Skipping ${options.filePath}: ${err.message}`);
|
|
66
|
+
return { source, points: [], runtimeNeeded: false };
|
|
67
|
+
}
|
|
58
68
|
},
|
|
59
69
|
|
|
60
70
|
remove(source) {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import * as acorn from 'acorn';
|
|
2
|
-
import { attachComments } from 'astravel';
|
|
2
|
+
import { defaultTraveler, attachComments } from 'astravel';
|
|
3
|
+
|
|
4
|
+
// Patch astravel bug: PropertyDefinition reuses MethodDefinition handler which
|
|
5
|
+
// calls this.go(node.value) without a null guard. Uninitialized class fields
|
|
6
|
+
// (e.g. `bar;`) have value: null, crashing the traversal.
|
|
7
|
+
defaultTraveler.PropertyDefinition = function (node, state) {
|
|
8
|
+
this.go(node.key, state);
|
|
9
|
+
if (node.value != null) {
|
|
10
|
+
this.go(node.value, state);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
15
|
* Parse JS source to ESTree AST with comments attached to nodes.
|
package/src/cli/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export function createCli() {
|
|
|
9
9
|
program
|
|
10
10
|
.name('flake-monster')
|
|
11
11
|
.description('Source-to-source test hardener, injects async delays to surface flaky tests')
|
|
12
|
-
.version('0.1
|
|
12
|
+
.version('0.3.1');
|
|
13
13
|
|
|
14
14
|
registerInjectCommand(program);
|
|
15
15
|
registerRestoreCommand(program);
|