Skip to content

Commit 7c32e63

Browse files
fix: tests
1 parent 945ea5a commit 7c32e63

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export function getDebuggerStartCommand(folder: string, args: string[]) {
2+
let testMonorepo = process.env.TEST_MONOREPO === 'true';
3+
if (testMonorepo) {
4+
testMonorepo = true;
5+
// just the last two part of the folder
6+
const folderParts = folder.split('/');
7+
const testProjectFolder =
8+
folderParts[folderParts.length - 2] +
9+
'/' +
10+
folderParts[folderParts.length - 1];
11+
args.push(`-m ${testProjectFolder}`);
12+
}
13+
14+
if (process.env.OBSERVABLE_MODE === 'true') {
15+
args.push('-o');
16+
}
17+
18+
args.push('-v');
19+
20+
let command = `node ${testMonorepo ? '' : '../../'}dist/lldebugger.mjs ${args?.join(' ')}`;
21+
22+
if (process.env.REAL_NPM === 'true') {
23+
console.log('Running the debugger with the real NPM');
24+
command = `lld ${args?.join(' ')}`;
25+
} else {
26+
console.log('Running the debugger with just genereted code');
27+
}
28+
return command;
29+
}

test/utils/removeInfra.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChildProcess, execSync } from 'child_process';
22
import { setTimeout } from 'timers/promises';
3+
import { getDebuggerStartCommand } from './getDebuggerStartCommand.js';
34

45
export async function removeInfra(
56
lldProcess: ChildProcess | undefined,
@@ -8,11 +9,7 @@ export async function removeInfra(
89
) {
910
lldProcess?.kill();
1011

11-
let command = `node ../../dist/lldebugger.mjs --remove ${args?.join(' ')}`;
12-
13-
if (process.env.REAL_NPM === 'true') {
14-
command = `lld --remove ${args?.join(' ')}`;
15-
}
12+
const command = getDebuggerStartCommand(folder, [...args, '--remove']);
1613

1714
await execSync(command, {
1815
cwd: folder,

test/utils/startDebugger.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { spawn } from 'child_process';
22
import { setTimeout } from 'timers/promises';
33
import { exec } from 'child_process';
44
import { promisify } from 'util';
5+
import { getDebuggerStartCommand } from './getDebuggerStartCommand.js';
56

67
export const execAsync = promisify(exec);
78

@@ -18,34 +19,8 @@ export async function startDebugger(folder: string, args: string[] = []) {
1819
async function startDebuggerInternal(folder: string, args: string[] = []) {
1920
console.log('Starting LLD...');
2021

21-
let testMonorepo = false;
22-
if (process.env.TEST_MONOREPO === 'true') {
23-
testMonorepo = true;
24-
// just the last two part of the folder
25-
const folderParts = folder.split('/');
26-
const testProjectFolder =
27-
folderParts[folderParts.length - 2] +
28-
'/' +
29-
folderParts[folderParts.length - 1];
30-
args.push(`-m ${testProjectFolder}`);
31-
}
32-
33-
if (process.env.OBSERVABLE_MODE === 'true') {
34-
args.push('-o');
35-
}
36-
37-
args.push('-v');
38-
39-
let command = `node ${
40-
testMonorepo ? '' : '../../'
41-
}dist/lldebugger.mjs ${args?.join(' ')}`;
42-
43-
if (process.env.REAL_NPM === 'true') {
44-
console.log('Running the debugger with the real NPM');
45-
command = `lld ${args?.join(' ')}`;
46-
} else {
47-
console.log('Running the debugger with just genereted code');
48-
}
22+
const testMonorepo = process.env.TEST_MONOREPO === 'true';
23+
const command = getDebuggerStartCommand(folder, args);
4924

5025
const lldProcess = spawn(command, {
5126
cwd: !testMonorepo ? folder : undefined,

0 commit comments

Comments
 (0)