Skip to content

Commit

Permalink
fix cyclical dependency test
Browse files Browse the repository at this point in the history
  • Loading branch information
khanayan123 committed Dec 19, 2023
1 parent 61876ee commit c5b0c74
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 7 additions & 0 deletions test/fixtures/cyclical-a.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { testB } from './cyclical-b.mjs';

export function testA() {
console.log("testA");
}

testB();
11 changes: 5 additions & 6 deletions test/fixtures/cyclical-b.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { testB } from './b.mjs';
import { testA } from './cyclical-a.mjs';

export function testA() {
console.log("testA");
}

testB();
export function testB() {
console.log("testB");
testA();
}
11 changes: 5 additions & 6 deletions test/other/assert-cyclical-dependency-failure.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { strictEqual } from 'assert'
const nodeProcess = spawn('node', [
'--loader',
'./hook.mjs',
'./test/fixtures/a.mjs'
'./test/fixtures/cyclical-a.mjs'
])

// expected output is 'testB\ntestA' but the actual output of this test is '' because
// the hook fails when running against files with cylical dependencies
// expected output should be 'testB\ntestA' but the hook fails when running against files
// with cylical dependencies
const expectedOutput = 'testB\ntestA'
const actualOutput = ''
let stdout = ''
let stderr = ''

Expand All @@ -27,6 +26,6 @@ nodeProcess.stderr.on('data', (data) => {
});

nodeProcess.on('close', (code) => {
strictEqual(stderr, '', 'There should be no errors on stderr')
strictEqual(stdout.trim(), actualOutput, 'The stdout should match the expected output')
// assert that the hook fails with a non-zero exit code
strictEqual(code, 1)
});

0 comments on commit c5b0c74

Please sign in to comment.