Skip to content

Commit

Permalink
[Threads] implement a toolset to work with threads #45
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Feb 3, 2021
1 parent 8f38385 commit 6417553
Show file tree
Hide file tree
Showing 17 changed files with 972 additions and 42 deletions.
231 changes: 190 additions & 41 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-clean": "^0.4.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-sourcemaps": "^3.0.0",
"merge-stream": "^2.0.0",
"mocha": "^7.2.0",
"nyc": "^15.1.0",
Expand Down
1 change: 1 addition & 0 deletions tests/Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const task_default = function() {
'web/**/*.js',
'ServiceWorker/**/*.js',
'traits/**/*.js',
'threading/**/*.js',
], { base: './', })
.pipe(sourcemaps.init())
.pipe(babel(babelConfig))
Expand Down
2 changes: 2 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ require('./util/array');

require('./rendering');

require('./threading');

require('./features');
47 changes: 47 additions & 0 deletions tests/threading/CurrentThread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-env mocha */

const expect = require('chai').expect;
const mochaVM = require('../../node/mochaVM');

module.exports = function() {
const vm = mochaVM({});

mochaVM.applyNodeEnv(vm);

vm.updateContext({
self: vm.getContext(),

addEventListener() {},
postMessage() {},

BroadcastChannel: function(name) { // eslint-disable-line object-shorthand
this.name = name;
},

Worker: function(sourcePath) { // eslint-disable-line object-shorthand
this.source = sourcePath;

this.postMessage = function() {};
},

MessagePort: function() { // eslint-disable-line object-shorthand
this.postMessage = function() {};

this.onmessage = {};
}
});

vm.runModule('../../testable/threading/lib/CurrentThread.js');

it('should be able to bootstrap the current thread', () => {
const { testResult } = vm.apply(() => {
/* globals CurrentThread */

CurrentThread.bootstrap();

global.testResult = CurrentThread;
});

expect(testResult).to.have.property('mainThread');
});
};
Loading

0 comments on commit 6417553

Please sign in to comment.