Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
test: add esm module test
Browse files Browse the repository at this point in the history
Ref #1291
  • Loading branch information
robertsLando committed Sep 30, 2021
1 parent 59125d1 commit 0e57862
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
49 changes: 49 additions & 0 deletions test/test-00-esm/main.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env node

'use strict';

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');
const os = require('os');

// ignore this test if nodejs <= 10 , as recent version of PNPM do not support nodejs=10
const MAJOR_VERSION = parseInt(process.version.match(/v([0-9]+)/)[1], 10);

if (MAJOR_VERSION < 14) {
console.log(
'skiping test as it requires nodejs >= 14',
MAJOR_VERSION
);
process.exit(0)
}

assert(__dirname === process.cwd());

const ext = process.platform === 'win32' ? '.exe' : '';

const target = process.argv[2] || 'host';
const input = './test.js';
const output = './test-output' + ext;

console.log('target = ', target);
utils.pkg.sync([
'--target',
target,
'--output',
output,
input,
]);

// check that produced executable is running and produce the expected output.
const log = utils.spawn.sync(output, [], {
cwd: path.dirname(output),
expect: 0,
});
assert(log === os.arch() + '\n');

// clean up
utils.vacuum.sync(output);

console.log('OK');
13 changes: 13 additions & 0 deletions test/test-00-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test-00-esm",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions test/test-00-esm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os from 'os';

console.log(os.arch());
7 changes: 5 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ function joinAndForward(d) {
const list = [];

if (flavor.match(/^test/)) {
list.push(joinAndForward(`${flavor}/main.js`));
list.push(
joinAndForward(`${flavor}/main.js`),
joinAndForward(`${flavor}/main.cjs`)
);
} else if (flavor === 'only-npm') {
list.push(joinAndForward('test-79-npm/main.js'));
} else {
list.push(joinAndForward('**/main.js'));
list.push(joinAndForward('**/main.js'), joinAndForward('**/main.cjs'));
if (flavor === 'no-npm') {
list.push('!' + joinAndForward('test-42-fetch-all'));
list.push('!' + joinAndForward('test-46-multi-arch'));
Expand Down

0 comments on commit 0e57862

Please sign in to comment.