Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using ES modules to define scenarios #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import yargs from 'yargs';

yargs
yargs(process.argv.slice(2))
.demandCommand(1, 'Use one of the above commands')
.command(
'list',
Expand All @@ -22,7 +22,7 @@ yargs
.array('require')
.option('matrix', { type: 'string' }),
async argv => {
let mod = await import('./list');
let mod = await import('./list.js');
await mod.printList(argv);
}
)
Expand Down Expand Up @@ -53,7 +53,7 @@ yargs
})
.array('require'),
async argv => {
let mod = await import('./output');
let mod = await import('./output.js');
await mod.output(argv);
}
)
Expand Down
13 changes: 9 additions & 4 deletions list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Scenario, seenScenarios } from '.';
import { sync as globSync } from 'glob';
import { Scenario, seenScenarios } from './index.js';
import glob from 'glob';
import { resolve } from 'path';
import { format } from 'util';

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

const { sync: globSync } = glob;

export interface ListParams {
files: string[];
require: string[] | undefined;
Expand All @@ -12,12 +17,12 @@ export interface ListParams {
export async function list(params: ListParams): Promise<Scenario[]> {
if (params.require) {
for (let r of params.require) {
require(require.resolve(r, { paths: [process.cwd()]}));
await import(require.resolve(r, { paths: [process.cwd()]}));
}
}
for (let pattern of params.files) {
for (let file of globSync(pattern)) {
require(resolve(file));
await import(resolve(file));
}
}
return seenScenarios;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scenario-tester": "./cli.js"
},
"main": "index.js",
"type": "module",
"scripts": {
"prepare": "tsc",
"start": "tsc --watch",
Expand Down
12 changes: 6 additions & 6 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Project } from 'fixturify-project';
import { Scenarios } from './index';
import { Scenarios } from './index.js';
import type { PreparedApp } from './index';
import Qunit = require('qunit');
import child_process = require('child_process');
import Qunit from 'qunit';
import child_process from 'child_process';

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

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

const scenarios = Scenarios.fromDir(__dirname + '/fixtures/app').expand({
const scenarios = Scenarios.fromDir('./fixtures/app').expand({
hello1,
hello2,
});
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"declaration": true,
"esModuleInterop": true,
"noUnusedLocals": true,
Expand Down