Skip to content

Commit

Permalink
fix: move QUEUE to globalThis scope; (#76)
Browse files Browse the repository at this point in the history
* chore: move `QUEUE` to `globalThis` scope;

- Closes #69

* fix(run): remove extra `UVU_QUEUE` setter;

- uvu/run ALWAYS loaded after core
  • Loading branch information
lukeed committed Nov 30, 2020
1 parent d126d2c commit e419ff9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions run/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { exec, QUEUE } = require('uvu');
const { exec } = require('uvu');

exports.run = async function (suites, opts={}) {
globalThis.UVU_DEFER = 1;

suites.forEach((suite, idx) => {
globalThis.UVU_QUEUE.push([suite.name]);
globalThis.UVU_INDEX = idx;
QUEUE.push([suite.name]);
require(suite.file);
});

Expand Down
4 changes: 2 additions & 2 deletions run/index.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { exec, QUEUE } from 'uvu';
import { exec } from 'uvu';

export async function run(suites, opts={}) {
let suite, idx=0;
globalThis.UVU_DEFER = 1;

for (suite of suites) {
QUEUE.push([suite.name]);
globalThis.UVU_INDEX = idx++;
globalThis.UVU_QUEUE.push([suite.name]);
await import('file:///' + suite.file);
}

Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ if (isNode = typeof process < 'u' && typeof process.stdout < 'u') {
hrtime = (now = performance.now()) => () => (performance.now() - now).toFixed(2) + 'ms';
}

globalThis.UVU_QUEUE = globalThis.UVU_QUEUE || [];
isCLI || UVU_QUEUE.push([null]);

const QUOTE = kleur.dim('"'), GUTTER = '\n ';
const FAIL = kleur.red('✘ '), PASS = kleur.gray('• ');
const IGNORE = /^\s*at.*(?:\(|\s)(?:node|(internal\/[\w/]*))/;
Expand Down Expand Up @@ -106,22 +109,19 @@ function setup(ctx, name = '') {
let copy = { ...ctx };
let run = runner.bind(0, copy, name);
Object.assign(ctx, context(copy.state));
QUEUE[globalThis.UVU_INDEX || 0].push(run);
UVU_QUEUE[globalThis.UVU_INDEX || 0].push(run);
};
return test;
}

export const QUEUE = [];
isCLI || QUEUE.push([null]);

export const suite = (name = '', state = {}) => setup(context(state), name);
export const test = suite();

export async function exec(bail) {
let timer = hrtime();
let done=0, total=0, skips=0, code=0;

for (let group of QUEUE) {
for (let group of UVU_QUEUE) {
if (total) write('\n');

let name = group.shift();
Expand Down
10 changes: 0 additions & 10 deletions test/uvu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import * as uvu from '../src/index';

const QUEUE = suite('QUEUE');

QUEUE('should be an Array', () => {
assert.instance(uvu.QUEUE, Array);
});

QUEUE.run();

// ---

const ste = suite('suite');

ste('should be a function', () => {
Expand Down

0 comments on commit e419ff9

Please sign in to comment.