Skip to content

Commit

Permalink
Improve naming around ambiguous items
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Sep 17, 2021
1 parent 6d939ec commit 4b10080
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions mochify/index.js
Expand Up @@ -24,7 +24,7 @@ async function mochify(options = {}) {
const mocha_runner = createMochaRunner(config.reporter || 'spec');
const { mochifyDriver } = resolveMochifyDriver(config.driver);

const [mocha, client, files] = await Promise.all([
const [mocha, client, resolved_spec] = await Promise.all([
readFile(require.resolve('mocha/mocha.js'), 'utf8'),
readFile(require.resolve('./client'), 'utf8'),
resolveSpec(config.spec)
Expand All @@ -36,7 +36,7 @@ async function mochify(options = {}) {
let server = null;
if (config.serve || config.esm) {
const _scripts = [mocha, configured_client];
const _modules = config.esm ? files : [];
const _modules = config.esm ? resolved_spec : [];
server = await startServer(
config.serve || process.cwd(),
Object.assign({ _scripts, _modules }, config.server_options)
Expand All @@ -47,7 +47,7 @@ async function mochify(options = {}) {
const driver_promise = mochifyDriver(driver_options);
const bundler_promise = config.esm
? Promise.resolve('')
: resolveBundle(config.bundle, files);
: resolveBundle(config.bundle, resolved_spec);

let driver, bundle;
try {
Expand Down
19 changes: 11 additions & 8 deletions mochify/lib/resolve-bundle.js
Expand Up @@ -6,18 +6,21 @@ const { parseArgsStringToArgv } = require('string-argv');

exports.resolveBundle = resolveBundle;

async function resolveBundle(command, files) {
if (typeof files === 'object' && typeof files.pipe === 'function') {
return bufferStream(files);
async function resolveBundle(command, resolved_spec) {
if (
typeof resolved_spec === 'object' &&
typeof resolved_spec.pipe === 'function'
) {
return bufferStream(resolved_spec);
}

if (!command) {
return concatFiles(files);
return concatFiles(resolved_spec);
}

const [cmd, ...args] = parseArgsStringToArgv(command);

const result = await execa(cmd, args.concat(files), {
const result = await execa(cmd, args.concat(resolved_spec), {
preferLocal: true
});

Expand All @@ -35,9 +38,9 @@ async function concatFiles(files) {

function bufferStream(stream) {
return new Promise((resolve, reject) => {
const bs = [];
stream.on('data', (chunk) => bs.push(chunk));
const buffers = [];
stream.on('data', (chunk) => buffers.push(chunk));
stream.on('error', (err) => reject(err));
stream.on('end', () => resolve(Buffer.concat(bs).toString()));
stream.on('end', () => resolve(Buffer.concat(buffers).toString('utf8')));
});
}

0 comments on commit 4b10080

Please sign in to comment.