-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Node.js CI | ||
on: | ||
pull_request: | ||
branches: [ "master" ] | ||
push: | ||
|
||
jobs: | ||
|
||
test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
env: | ||
YARN_IGNORE_NODE: 1 | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x, 22.x] | ||
|
||
steps: | ||
|
||
- name: 'Checkout the repository' | ||
uses: actions/checkout@v4 | ||
|
||
- name: Test with Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Compile TypeScript test code | ||
run: npm run compile-test | ||
|
||
- name: Run tests | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"spec": ["test/*.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const testValue = 42; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {describe, it} from 'mocha'; | ||
import * as chai from 'chai'; | ||
import * as path from 'path'; | ||
import {loadEsm} from '../index.js'; | ||
|
||
const {expect} = chai; | ||
|
||
describe('loadEsm', function () { | ||
it('should load an ES module dynamically', async function () { | ||
// Mock ES module file for testing. | ||
const modulePath = path.join(__dirname, 'mock.mjs'); | ||
|
||
// Load the ES module dynamically using loadEsm. | ||
const esmModule = await loadEsm(`file://${modulePath}`); | ||
|
||
// Verify the loaded module. | ||
expect(esmModule).to.be.an('module'); | ||
expect(esmModule.testValue).to.equal(42); | ||
}); | ||
|
||
it('should throw an error if the module path is invalid', async function () { | ||
const invalidPath = 'file:///non-existent-module.js'; | ||
|
||
try { | ||
await loadEsm(invalidPath); | ||
// If no error is thrown, this test should fail. | ||
throw new Error('Expected loadEsm to throw an error, but it did not.'); | ||
} catch (error) { | ||
// Verify that the error is thrown. | ||
expect(error).to.be.an('error'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"inlineSources": false, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "ES2017" | ||
} | ||
} |