Skip to content

Commit

Permalink
chore: adjust test for Node <14
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Sep 15, 2022
1 parent 0dafd3a commit 2481e5f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/node/stage_2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { pathToFileURL } from 'url'
import test from 'ava'
import del from 'del'
import { execa } from 'execa'
import semver from 'semver'
import tmp from 'tmp-promise'

import { getLocalEntryPoint } from '../../node/formats/javascript.js'
Expand All @@ -31,7 +32,10 @@ test('`getLocalEntryPoint` returns a valid stage 2 file for local development',
await fs.writeFile(printerPath, printer)
process.env.NETLIFY_EDGE_BOOTSTRAP = pathToFileURL(printerPath).toString()

const functions = [{ name: 'func1', path: join(tmpDir, 'func1.mjs'), response: 'Hello from function 1' }]
const functions = [
{ name: 'func1', path: join(tmpDir, 'func1.mjs'), response: 'Hello from function 1' },
{ name: 'func2', path: join(tmpDir, 'func2.mjs'), response: 'Hello from function 2' },
]

for (const func of functions) {
const contents = `export default () => ${JSON.stringify(func.response)}`
Expand All @@ -47,6 +51,16 @@ test('`getLocalEntryPoint` returns a valid stage 2 file for local development',

await fs.writeFile(stage2Path, stage2)

// In Node <14, we're not able to actually load the stage 2 because ESM is
// not supported. The best we can do is to naively look for some assignments.
if (semver.lt(process.version.slice(1), '14.0.0')) {
for (const func of functions) {
t.true(stage2.includes(`metadata["${func.name}"] = {"url":"${pathToFileURL(func.path).toString()}"}`))
}

return
}

const { stdout, stderr } = await execa('node', [stage2Path])

t.is(stderr, '')
Expand Down

0 comments on commit 2481e5f

Please sign in to comment.