Skip to content

Commit

Permalink
esbuild integration
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Mar 14, 2021
1 parent 97fedc8 commit 51014f6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 36 deletions.
2 changes: 0 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ process.title = 'qunitx';
}

let config = await parseCliFlags();
console.log(config);

return await run(config);
})();
85 changes: 57 additions & 28 deletions lib/commands/run.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
// test/foo.js test/bar.js test/feedback/**/*.ts test/logout app/e2e/submit-\w+.ts

// let tree = Object.assign(tree, directoryReader(config, inputs, (file) => {
// import(`${file}`);
// }));

import fs from 'fs/promises';
import chalk from 'chalk';
import esbuild from 'esbuild';
import setupWebsocketServer from '../setup/websocket-server.js';
import setupBrowser from '../setup/browser.js';
import parseFsInputs from '../utils/parse-fs-inputs.js';
import TAPDisplayFinalResult from '../tap/display-final-result.js';

export default async function(config) {
const { browser, fileOrFolderInputs } = config;

if (!browser) {
const QUnit = (await import('../setup-node-js-environment.js')).default;

fileOrFolderInputs.forEach(async (fileOrFolder, index) => {
// TODO: handle/format globs

try {
const entry = await fs.stat(fileOrFolder);

if (entry.isDirectory()) {
console.log(entry, ' is directory');
} else if (entry.isFile()) { // handle what to do when its .ts
await import(`${process.cwd()}/${fileOrFolder}`);
}
} catch (error) {
console.log(error);

return process.exit(1);
}

if (index === (fileOrFolderInputs.length - 1)) {
if (!browser) {
console.log('TAP version 13');
QUnit.start();
}
}
const { browser, fileOrFolderInputs, projectRoot } = config;

if (browser) {
let COUNTER = { testCount: 0, failCount: 0, skipCount: 0, passCount: 0 };
let WebSocketServer = await setupWebsocketServer(COUNTER, config);
const fsTree = await parseFsInputs(fileOrFolderInputs, {}, async(targetPath, fsEntry) => {
fsEntry.executed = false;
}, config);

await esbuild.build({
stdin: {
contents: Object.keys(fsTree).reduce((result, fileAbsolutePath) => {
return result + `import "${fileAbsolutePath}";`
}, ''),
resolveDir: process.cwd()
},
bundle: true,

outfile: `${projectRoot}/dist/tests.js`
});

let allTestCode = (await fs.readFile(`${projectRoot}/dist/tests.js`)).toString();
let MBER_TEST_TIME_COUNTER = (function() {
const startTime = new Date();

return {
start: startTime,
stop: () => +(new Date()) - (+startTime)
};
})();
let { browser, server } = await setupBrowser(config, allTestCode);
let TIME_TAKEN = MBER_TEST_TIME_COUNTER.stop()

TAPDisplayFinalResult(COUNTER, TIME_TAKEN);

await server.close();
await browser.close();

process.exit();
} else {
const QUnit = (await import('../setup/node-js-environment.js')).default;
const fsTree = await parseFsInputs(fileOrFolderInputs, {}, async(targetPath, fsEntry) => {
await import(targetPath);
fsEntry.executed = true;
}, config);
console.log('TAP version 13');
QUnit.start();
}
}
3 changes: 1 addition & 2 deletions lib/setup/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import Puppeteer from 'puppeteer';

const defaults = { port: 4200, debug: false, socketPort: 65511, testTimeout: 10000 };

export default async function(options = { port: 4200, debug: false, socketPort: 65511 }) {
export default async function(options = { port: 4200, debug: false, socketPort: 65511 }, boilerplateQunit='') {
// TODO: make these async
let boilerplateQunit = fs.readFileSync(`${process.cwd()}/test.js`).toString();
let QUnitCSS = fs.readFileSync(`${process.cwd()}/node_modules/qunit/qunit/qunit.css`).toString();
// TODO: make these async end

Expand Down
4 changes: 3 additions & 1 deletion lib/utils/parse-cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default async function() {
return Object.assign(result, { watch: parseBoolean(arg.split('=')[1]) });
} else if (arg.startsWith('--failfast') || arg.startsWith('--failFast')) {
return Object.assign(result, { failFast: parseBoolean(arg.split('=')[1]) });
} else if (arg.startsWith('--timeout')) {
return Object.assign(result, { timeout: arg.split('=')[1] || '10000' });
} else if (arg.startsWith('--reporter')) {
return Object.assign(result, { reporter: arg.split('=')[1] || 'spec' });
} else if (arg.startsWith('--coverage')) {
Expand All @@ -27,7 +29,7 @@ export default async function() {
return result;
}, { fileOrFolderInputs: [] });

console.log('providedFlags', providedFlags);
// console.log('providedFlags', providedFlags);
return Object.assign(defaultValues, projectConfig, providedFlags);
}

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"chalk": "^4.1.0",
"esbuild": "^0.9.2",
"klaw": "^3.0.0",
"puppeteer": "^5.5.0",
"qunit": "^2.13.0",
Expand Down
4 changes: 1 addition & 3 deletions test/helpers/failing-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import QUnit from 'qunit';

const { module, test } = QUnit;
import { module, test } from '../../index.js';

module('{{moduleName}}', function(hooks) {
test('assert true works', function (assert) {
Expand Down

0 comments on commit 51014f6

Please sign in to comment.