Skip to content

Commit f018c1e

Browse files
petermmampcode-com
andauthored
fix: use dynamic import in tests to prevent ESM hoisting race (#429)
Static ESM imports are hoisted above top-level statements, causing setup-beam.js to evaluate its main() guard before process.env.NODE_ENV is set to 'test'. This triggered core.setFailed() during module load, setting process.exitCode=1 and failing the test file even though all individual test cases passed. Switch setup-beam.js to a dynamic await import() so that the env and input setup runs first, ensuring the NODE_ENV='test' guard works correctly. Amp-Thread-ID: https://ampcode.com/threads/T-019ce36a-a18f-7494-ac0a-c094a84f06ad Co-authored-by: Amp <amp@ampcode.com>
1 parent d843ebb commit f018c1e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test/setup-beam.test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import assert from 'node:assert'
2+
import http from 'node:http'
3+
import fs from 'node:fs'
4+
import os from 'node:os'
5+
import path from 'node:path'
6+
import { describe, it } from 'node:test'
7+
import * as csv from 'csv-parse/sync'
8+
import elixirMatchers from '../matchers/elixir-matchers.json' with { type: 'json' }
9+
const { problemMatcher } = elixirMatchers
10+
111
process.env.NODE_ENV = 'test'
212

313
simulateInput('otp-version', '25.1.2')
@@ -9,16 +19,7 @@ simulateInput('install-hex', 'true')
919
simulateInput('github-token', process.env.GITHUB_TOKEN)
1020
simulateInput('hexpm-mirrors', 'https://builds.hex.pm', { multiline: true })
1121

12-
import assert from 'node:assert'
13-
import http from 'node:http'
14-
import fs from 'node:fs'
15-
import os from 'node:os'
16-
import path from 'node:path'
17-
import { describe, it } from 'node:test'
18-
import * as csv from 'csv-parse/sync'
19-
import setupBeam from '../src/setup-beam.js'
20-
import elixirMatchers from '../matchers/elixir-matchers.json' with { type: 'json' }
21-
const { problemMatcher } = elixirMatchers
22+
const { default: setupBeam } = await import('../src/setup-beam.js')
2223

2324
const matrix = {
2425
otp: {

0 commit comments

Comments
 (0)