Skip to content

Commit

Permalink
fix code to work with modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed May 30, 2023
1 parent b1a19f5 commit d0f7d52
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
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

0 comments on commit d0f7d52

Please sign in to comment.