Skip to content

Commit

Permalink
add tests for explicit modules and commonjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed May 29, 2023
1 parent f0a9105 commit 4b749ae
Show file tree
Hide file tree
Showing 4 changed files with 833 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"scripts": {
"prepare": "tsc",
"start": "tsc --watch",
"test": "qunit test.js"
"test": "npm-run-all test:*",
"test:js": "qunit test.js",
"test:modules": "qunit test-modules.mjs",
"test:commonjs": "qunit test-commonjs.cjs"
},
"files": [
"*.js",
Expand All @@ -37,6 +40,7 @@
"@types/qunit": "^2.11.3",
"@types/tmp": "^0.2.0",
"@types/yargs": "^16.0.0",
"npm-run-all": "^4.1.5",
"qunit": "^2.18.0",
"typescript": "^4.4.2"
}
Expand Down
62 changes: 62 additions & 0 deletions test-commonjs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_js_1 = require("./index.js");
const qunit_1 = __importDefault(require("qunit"));
const child_process_1 = __importDefault(require("child_process"));
function hello1(project) {
project.linkDependency('hello', {
baseDir: './fixtures',
resolveName: 'hello1',
});
}
function hello2(project) {
project.linkDependency('hello', {
baseDir: './fixtures',
resolveName: 'hello',
});
}
const scenarios = index_js_1.Scenarios.fromDir('./fixtures/app').expand({
hello1,
hello2,
});
scenarios.forEachScenario((scenario) => {
qunit_1.default.module(scenario.name, (hooks) => {
hooks.before(async function () {
this.app = await scenario.prepare();
});
qunit_1.default.test('yarn test', async function (assert) {
const result = await this.app.execute('yarn --silent test');
assert.equal(result.stdout, `TAP version 13
ok 1 project > createHello
1..1
# pass 1
# skip 0
# todo 0
# fail 0
`);
});
qunit_1.default.test('yarn bin inside app', async function (assert) {
let result = await this.app.execute('yarn --silent bin');
const yarnBin = result.stdout.trimRight();
assert.ok(yarnBin.startsWith(this.app.dir));
result = await this.app.execute('yarn --silent exec which qunit');
assert.ok(result.stdout.startsWith(yarnBin));
});
qunit_1.default.test('check scenario', async function (assert) {
let result = await this.app.execute(`node -p 'require("./index").polyfilled'`);
assert.equal(result.stdout.trim(), ('hello1' === scenario.name).toString());
});
});
});
qunit_1.default.module('cli', () => {
qunit_1.default.test('list', (assert) => {
assert.deepEqual(child_process_1.default
.execFileSync(process.execPath, ['cli.js', 'list', '--files', 'test.js', '--matrix'], { encoding: 'utf8' })
.trimRight()
.split('\n'), ['hello1', 'hello2']);
});
});
//# sourceMappingURL=test.js.map
89 changes: 89 additions & 0 deletions test-modules.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Project } from 'fixturify-project';
import { Scenarios } from './index.js';
import Qunit from 'qunit';
import child_process from 'child_process';

function hello1(project) {
project.linkDependency('hello', {
baseDir: './fixtures',
resolveName: 'hello1',
});
}

function hello2(project) {
project.linkDependency('hello', {
baseDir: './fixtures',
resolveName: 'hello',
});
}

const scenarios = Scenarios.fromDir('./fixtures/app').expand({
hello1,
hello2,
});

scenarios.forEachScenario((scenario) => {
Qunit.module(scenario.name, (hooks) => {
hooks.before(async function ({ app }) {
this.app = await scenario.prepare();
});

Qunit.test(
'yarn test',
async function (assert) {
const result = await this.app.execute('yarn --silent test');
assert.equal(
result.stdout,
`TAP version 13
ok 1 project > createHello
1..1
# pass 1
# skip 0
# todo 0
# fail 0
`
);
}
);

Qunit.test(
'yarn bin inside app',
async function (assert) {
let result = await this.app.execute('yarn --silent bin');
const yarnBin = result.stdout.trimRight();
assert.ok(yarnBin.startsWith(this.app.dir));
result = await this.app.execute('yarn --silent exec which qunit');
assert.ok(result.stdout.startsWith(yarnBin));
}
);

Qunit.test(
'check scenario',
async function (assert) {
let result = await this.app.execute(
`node -p 'require("./index").polyfilled'`
);
assert.equal(
result.stdout.trim(),
('hello1' === scenario.name).toString()
);
}
);
});
});

Qunit.module('cli', () => {
Qunit.test('list', (assert) => {
assert.deepEqual(
child_process
.execFileSync(
process.execPath,
['cli.js', 'list', '--files', 'test-modules.mjs', '--matrix'],
{ encoding: 'utf8' }
)
.trimRight()
.split('\n'),
['hello1', 'hello2']
);
});
});
Loading

0 comments on commit 4b749ae

Please sign in to comment.