Skip to content

Commit

Permalink
Move from Karma to Karmatic! :)
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Jan 24, 2018
1 parent 8d39f33 commit afaa20b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 124 deletions.
29 changes: 6 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"scripts": {
"build": "microbundle --inline none --format cjs --no-compress src/*.js",
"prepublishOnly": "npm run build",
"dev": "webpack-dev-server --no-hot --config test/webpack.config.js",
"release": "npm t && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"test": "npm run build && webpack --config test/webpack.config.js && npm run -s mocha",
"mocha": "concurrently -r --kill-others \"serve -p 42421 test/dist\" \"sleep 1 && mocha-chrome http://localhost:42421\""
"dev": "karmatic watch --no-headless",
"test": "npm run build && karmatic",
"release": "npm t && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
},
"eslintConfig": {
"extends": "eslint-config-developit",
Expand All @@ -34,26 +33,10 @@
"author": "Jason Miller <[email protected]> (http://jasonformat.com)",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"concurrently": "^3.5.1",
"css-loader": "^0.28.8",
"eslint": "^4.15.0",
"eslint": "^4.16.0",
"eslint-config-developit": "^1.1.1",
"exports-loader": "^0.6.4",
"fast-async": "^6.3.0",
"html-webpack-plugin": "^2.30.1",
"microbundle": "^0.4.1",
"mocha": "^4.1.0",
"mocha-chrome": "^1.0.3",
"mocha-puppeteer": "^0.13.0",
"serve": "^6.4.4",
"style-loader": "^0.19.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.10.1"
"karmatic": "^1.0.5",
"microbundle": "^0.4.2"
},
"dependencies": {
"loader-utils": "^1.1.0"
Expand Down
52 changes: 22 additions & 30 deletions test/src/index.js → test/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import 'babel-polyfill';
import './other';
import 'mocha/mocha.css';
import mocha from 'exports-loader?mocha!mocha/mocha';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import Worker from 'workerize-loader?ready&name=test!./worker';
import InlineWorker from 'workerize-loader?ready&inline&name=test!./worker';

document.body.appendChild(document.createElement('div')).id = 'mocha';
mocha.setup('bdd');
setTimeout(mocha.run);

chai.use(chaiAsPromised);

let worker = window.worker = new Worker();
console.log(worker);

describe('worker', () => {
let worker;

it('should be an instance of Worker', () => {
expect(worker).to.be.an.instanceof(window.Worker);
worker = new Worker();
expect(worker).toEqual(jasmine.any(window.Worker));
});
it('worker.foo()', () => {
expect(worker.foo()).to.eventually.equal(1);

it('worker.foo()', async () => {
expect(await worker.foo()).toBe(1);
});
it('worker.bar()', () => {
expect(worker.bar('a', 'b')).to.eventually.equal('a [bar:3] b');

it('worker.bar()', async () => {
let out = await worker.bar('a', 'b');
expect(out).toEqual('a [bar:3] b');
});

it('should fire ready event', done => {
Expand All @@ -34,7 +26,7 @@ describe('worker', () => {
function fin() {
if (isDone) return;
isDone = true;
expect(called).to.equal(true, 'fired "ready" event');
expect(called).toEqual(true);
done();
}
worker.addEventListener('ready', () => {
Expand All @@ -54,20 +46,20 @@ describe('async/await demo', () => {
await worker.ready;
elapsed = Date.now()-start;
console.log(`new Worker() [${elapsed}ms]`);
expect(elapsed).to.be.lessThan(300);
expect(elapsed).toBeLessThan(300);

let one = await worker.foo();
elapsed = Date.now()-start;
console.log(`await worker.foo() [${elapsed}ms]: `, one);
expect(one).to.equal(1);
expect(Date.now()-start).to.be.lessThan(300); // @todo why the overhead here?
expect(one).toEqual(1);
expect(Date.now()-start).toBeLessThan(300); // @todo why the overhead here?

start = Date.now();
let two = await worker.bar(1, 2);
elapsed = Date.now()-start;
console.log(`await worker.bar(1, 2) [${elapsed}ms]: `, two);
expect(two).to.equal('1 [bar:3] 2');
expect(Date.now()-start).to.be.lessThan(20);
expect(two).toEqual('1 [bar:3] 2');
expect(Date.now()-start).toBeLessThan(20);
});

it('inline worker', async () => {
Expand All @@ -77,20 +69,20 @@ describe('async/await demo', () => {
await worker.ready;
elapsed = Date.now()-start;
console.log(`new InlineWorker() [${elapsed}ms]`);
expect(elapsed).to.be.lessThan(300);
expect(elapsed).toBeLessThan(300);

start = Date.now();
let one = await worker.foo();
elapsed = Date.now()-start;
console.log(`await worker.foo() [${elapsed}ms]: `, one);
expect(one).to.equal(1);
expect(elapsed).to.be.lessThan(20);
expect(one).toEqual(1);
expect(elapsed).toBeLessThan(20);

start = Date.now();
let two = await worker.bar(1, 2);
elapsed = Date.now()-start;
console.log(`await worker.bar(1, 2) [${elapsed}ms]: `, two);
expect(two).to.equal('1 [bar:3] 2');
expect(elapsed).to.be.lessThan(20);
expect(two).toEqual('1 [bar:3] 2');
expect(elapsed).toBeLessThan(20);
});
});
71 changes: 0 additions & 71 deletions test/webpack.config.js

This file was deleted.

0 comments on commit afaa20b

Please sign in to comment.