Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Oct 27, 2023
1 parent 4d5e97d commit 1b490a1
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 24 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ export class Scenarios {
}
}

export const seenScenarios: Scenario[] = [];
global.scenarioTesterSeenScenarios = [];

export class Scenario {
constructor(
public name: string,
private callbackCreateProject: CallbackCreateProject,
private mutators: CallbackMutateProject[]
) {
seenScenarios.push(this);
global.scenarioTesterSeenScenarios.push(this);
}

async prepare(outdir?: string): Promise<PreparedApp> {
Expand Down
17 changes: 13 additions & 4 deletions list.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Scenario, seenScenarios } from './index.js';
import { Scenario } 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);
// import { createRequire } from 'node:module';
// const require = createRequire(import.meta.url);

const { sync: globSync } = glob;

Expand All @@ -15,8 +15,17 @@ export interface ListParams {
}

export async function list(params: ListParams): Promise<Scenario[]> {
debugger
if (params.require) {
for (let r of params.require) {
let require;
if (typeof import.meta !== undefined) {
const { default: { createRequire } } = await(import('node:module'));
require = createRequire(require('url').pathToFileURL(__filename).toString());
} else {
require = global.require;
}

await import(require.resolve(r, { paths: [process.cwd()]}));
}
}
Expand All @@ -25,7 +34,7 @@ export async function list(params: ListParams): Promise<Scenario[]> {
await import(resolve(file));
}
}
return seenScenarios;
return global.scenarioTesterSeenScenarios;
}

export async function printList(params: ListParams) {
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
},
"type": "module",
"scripts": {
"prepare": "tsc",
"prepare": "yarn build",
"build": "concurrently --no-color \"npm:build:*\" --names \"build:\"",
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:types": "tsc -p tsconfig.types.json",
"start": "tsc --watch",
"test": "concurrently --no-color \"npm:test:*\" --names \"test:\"",
"test:ts": "node --loader ts-node/esm node_modules/.bin/qunit --require ts-node/register tests/test.ts",
Expand Down Expand Up @@ -61,12 +65,12 @@
},
"exports": {
".": {
"import": "./build/index.js"
"import": "./build/mjs/index.js"
},
"./*": {
"types": "./build/*.d.ts",
"import": "./build/*.js",
"default": "./build/*.js"
"types": "./build/types/*.d.ts",
"import": "./build/mjs/*.js",
"default": "./build/cjs/*.js"
}
}
}
11 changes: 4 additions & 7 deletions tests/test.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"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 { Scenarios } = require('../');
const qunit_1 = __importDefault(require("qunit"));
const child_process_1 = __importDefault(require("child_process"));
function hello1(project) {
Expand All @@ -18,7 +15,7 @@ function hello2(project) {
resolveName: 'hello',
});
}
const scenarios = index_js_1.Scenarios.fromDir('./fixtures/app').expand({
const scenarios = Scenarios.fromDir('./fixtures/app').expand({
hello1,
hello2,
});
Expand Down Expand Up @@ -59,4 +56,4 @@ qunit_1.default.module('cli', () => {
.split('\n'), ['hello1', 'hello2']);
});
});
//# sourceMappingURL=test.js.map
//# sourceMappingURL=test.js.map
2 changes: 1 addition & 1 deletion tests/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ok 1 project > createHello

Qunit.module('cli', () => {
Qunit.test('list', async (assert) => {
const result = await execa('npx', ['.', 'list', '--files', 'tests/test.mjs', '--matrix'])
const result = await execa('node', ['build/cli.js', 'list', '--files', 'tests/test.mjs', '--matrix'])

const { stdout } = result;
assert.deepEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Project } from 'fixturify-project';
import { Scenarios } from '../index.js';
import { Scenarios } from '../';
import type { PreparedApp } from '../index.js';
import Qunit from 'qunit';
import execa from 'execa';
Expand Down Expand Up @@ -79,7 +79,7 @@ Qunit.module('cli', () => {
Qunit.test('list', async (assert) => {
// I tried to test this using the ts file dirrectly but I couldn't get ts-node/require to work correctly
// so I'm just testing against the compiled esm output
const result = await execa('npx', ['.', 'list', '--files', './build/tests/test.js', '--matrix'])
const result = await execa('node', ['build/cli.js', 'list', '--files', './build/tests/test.js', '--matrix'])

const { stdout } = result;
assert.deepEqual(
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./build/cjs",
"module": "commonjs",
}
}
7 changes: 7 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./build/esm",
"module": "ES2020",
}
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"outDir": "./build/",
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"declaration": true,
"esModuleInterop": true,
Expand All @@ -17,7 +15,8 @@
"strict": true
},
"include": [
"*.ts"
"*.ts",
"types/*"
],
"exclude": [
"node_modules/**/*",
Expand Down
7 changes: 7 additions & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Scenario } from "..";


declare global {
// eslint-disable-next-line no-var
var scenarioTesterSeenScenarios: Scenario[];
}

0 comments on commit 1b490a1

Please sign in to comment.