Skip to content

Commit

Permalink
fix: repair cleanup testbed
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless authored and SGrueber committed Jul 19, 2022
1 parent d1258fb commit c824159
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions scripts/cleanup-testbed.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync, spawnSync } from 'child_process';
import { existsSync, statSync } from 'fs';
import { copyFileSync, existsSync, statSync } from 'fs';
import glob from 'glob';
import minimatch from 'minimatch';
import runAll from 'npm-run-all';
Expand Down Expand Up @@ -92,13 +92,20 @@ if (args.length === 0) {
console.log('searching for tests in project');
files = glob.sync(jestPathPattern, { ignore: ['node_modules/**'] });
} else if (args.length === 1) {
if (!minimatch(normalize(args[0]), jestProjects)) {
const normalizedPath = normalize(args[0]);
let statRes;
try {
statRes = statSync(normalizedPath);
} catch (err) {
console.warn(`File "${normalizedPath}" doesn't exist.`);
}
if (!minimatch(normalizedPath, jestProjects)) {
console.log('using', args[0], 'as git-rev');
files = findTests(spawnSync('git', ['--no-pager', 'diff', args[0], '--name-only']).stdout.toString().split('\n'));
} else if (statSync(normalize(args[0])).isDirectory()) {
} else if (statRes?.isDirectory()) {
console.log('using', args[0], 'as folder');
files = glob.sync(join(args[0], jestPattern));
} else if (statSync(normalize(args[0])).isFile()) {
} else if (statRes?.isFile()) {
files = findTests(args);
} else {
console.error('cannot interpret argument as git revision, folder or test file');
Expand Down Expand Up @@ -184,7 +191,7 @@ if (!files.length) {

// write snapshot file of copy
if (existsSync(fileSnapshotPath) && !existsSync(copySnapshotPath)) {
execSync(`npx jest -i ${copyPath}`, { stdio: 'ignore' });
copyFileSync(fileSnapshotPath, copySnapshotPath);
}

for (const node of copy.forEachDescendantAsArray()) {
Expand Down

0 comments on commit c824159

Please sign in to comment.