@parcel/workers 2.0.0-nightly.92 → 2.0.0-nightly.934

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- const WorkerFarm = require('../../../').default;
1
+ const WorkerFarm = require('../../../src/WorkerFarm').default;
2
2
 
3
3
  function run() {
4
4
  if (WorkerFarm.isWorker()) {
@@ -1,4 +1,4 @@
1
- const WorkerFarm = require('../../../').default;
1
+ const WorkerFarm = require('../../../src/WorkerFarm').default;
2
2
  const Logger = require('@parcel/logger').default;
3
3
 
4
4
  function run() {
@@ -0,0 +1,5 @@
1
+ function run(workerApi, ref) {
2
+ return ref === workerApi.resolveSharedReference(workerApi.getSharedReference(ref));
3
+ }
4
+
5
+ exports.run = run;
@@ -1,5 +1,5 @@
1
- function run(_, handle) {
2
- return handle();
1
+ function run(workerApi, handle) {
2
+ return workerApi.runHandle(handle, []);
3
3
  }
4
4
 
5
5
  exports.run = run;
@@ -1,9 +1,9 @@
1
1
  import Logger from '@parcel/logger';
2
2
  import assert from 'assert';
3
- import WorkerFarm from '../';
3
+ import WorkerFarm from '../src';
4
4
 
5
- describe('WorkerFarm', function() {
6
- this.timeout(20000);
5
+ describe('WorkerFarm', function () {
6
+ this.timeout(30000);
7
7
 
8
8
  it('Should start up workers', async () => {
9
9
  let workerfarm = new WorkerFarm({
@@ -132,7 +132,7 @@ describe('WorkerFarm', function() {
132
132
  await workerfarm.end();
133
133
  });
134
134
 
135
- it('Forwards stdio from the child process and levels event source if patchConsole is true', async () => {
135
+ it('Forwards stdio from the child process and levels event source if shouldPatchConsole is true', async () => {
136
136
  let events = [];
137
137
  let logDisposable = Logger.onLog(event => events.push(event));
138
138
 
@@ -140,7 +140,7 @@ describe('WorkerFarm', function() {
140
140
  warmWorkers: true,
141
141
  useLocalWorker: false,
142
142
  workerPath: require.resolve('./integration/workerfarm/console.js'),
143
- patchConsole: true,
143
+ shouldPatchConsole: true,
144
144
  });
145
145
 
146
146
  await workerfarm.run();
@@ -291,6 +291,25 @@ describe('WorkerFarm', function() {
291
291
  assert.equal(result, 'Shared reference does not exist');
292
292
  });
293
293
 
294
+ it('Should resolve shared references in workers', async () => {
295
+ let workerfarm = new WorkerFarm({
296
+ warmWorkers: true,
297
+ useLocalWorker: false,
298
+ workerPath: require.resolve(
299
+ './integration/workerfarm/resolve-shared-reference.js',
300
+ ),
301
+ });
302
+
303
+ let sharedValue = 'Something to be shared';
304
+ let {ref, dispose} = await workerfarm.createSharedReference(sharedValue);
305
+
306
+ assert.equal(workerfarm.workerApi.resolveSharedReference(sharedValue), ref);
307
+ assert.ok(await workerfarm.run(ref));
308
+
309
+ await dispose();
310
+ assert(workerfarm.workerApi.resolveSharedReference(sharedValue) == null);
311
+ });
312
+
294
313
  it('Should support shared references in local worker', async () => {
295
314
  let workerfarm = new WorkerFarm({
296
315
  warmWorkers: true,
@@ -309,6 +328,25 @@ describe('WorkerFarm', function() {
309
328
  assert.equal(result, 'Shared reference does not exist');
310
329
  });
311
330
 
331
+ it('should resolve shared references in local worker', async () => {
332
+ let workerfarm = new WorkerFarm({
333
+ warmWorkers: true,
334
+ useLocalWorker: true,
335
+ workerPath: require.resolve(
336
+ './integration/workerfarm/resolve-shared-reference.js',
337
+ ),
338
+ });
339
+
340
+ let sharedValue = 'Something to be shared';
341
+ let {ref, dispose} = await workerfarm.createSharedReference(sharedValue);
342
+
343
+ assert.equal(workerfarm.workerApi.resolveSharedReference(sharedValue), ref);
344
+ assert.ok(await workerfarm.run(ref));
345
+
346
+ await dispose();
347
+ assert(workerfarm.workerApi.resolveSharedReference(sharedValue) == null);
348
+ });
349
+
312
350
  it('Should dispose of shared references when ending', async () => {
313
351
  let workerfarm = new WorkerFarm({
314
352
  warmWorkers: true,