t2ym/scenarist

Support module context

Closed this issue · 1 comments

t2ym commented

Support module context, i.e., non-global Suite class

// test.js
let assert = require('chai').assert;
let Suite = require('scenarist/Suite.min.js');
require('./scope1.js')(Suite, assert);
require('./scope2.js')(Suite, assert);

for (let scope in Suite.scopes) {
  Suite.scopes[scope].test.forEach(function (tests, index) {
    Suite.scopes[scope].run(index);
  });
}
// scope1.js
module.exports = function (Suite, assert) {
  let scope1 = new Suite('scope1');
  scope1.test = ...
  return scope1; // optional since scope1 === Suite.scopes.scope1
}
t2ym commented

Support ES6 modules

Current solution depends on rollup powered by these plugins:

rollup-plugin-async
rollup-plugin-commonjs
rollup-plugin-node-resolve
rollup-plugin-node-builtins

ES6 modules without globals

// test.mjs
import chai from 'chai';
import Suite from 'scenarist'; // resolves to 'scenarist/Suite.mjs'
import scope1 from './scope1.mjs';
import scope2 from './scope2.mjs';

let assert = chai.assert;
scope1(Suite, assert);
scope2(Suite, assert);

for (let scope in Suite.scopes) {
  Suite.scopes[scope].test.forEach(function (tests, index) {
    Suite.scopes[scope].run(index);
  });
}
// scope1.mjs
export default function (Suite, assert) {
  let scope1 = new Suite('scope1');
  scope1.test = ...
  return scope1; // optional since scope1 === Suite.scopes.scope1
}