diff --git a/src/index.js b/src/index.js index db75312..01b019d 100644 --- a/src/index.js +++ b/src/index.js @@ -128,7 +128,12 @@ loader.pitch = function(request) { let key = entries[0].entryModule.nameForCondition(); let contents = compilation.assets[worker.file].source(); - let exports = Object.keys(CACHE[key] || {}); + let exports = Array.from( + new Set([ + ...Object.keys(CACHE[key] || {}), + ...entries[0].entryModule.buildMeta.providedExports + ]) + ); // console.log('Workerized exports: ', exports.join(', ')); diff --git a/test/src/and-the-other.js b/test/src/and-the-other.js new file mode 100644 index 0000000..c9ece14 --- /dev/null +++ b/test/src/and-the-other.js @@ -0,0 +1,9 @@ +export function otherOtherFoo() { + return 2; +} + +export function anyFoo() { + return 4; +} + +export const otherOtherBar = 3; diff --git a/test/src/common.js b/test/src/common.js new file mode 100644 index 0000000..c7b6a1f --- /dev/null +++ b/test/src/common.js @@ -0,0 +1,3 @@ +exports.tragedy = function tragedy() { + return 'common'; +}; diff --git a/test/src/index.test.js b/test/src/index.test.js index 0b1bfc8..35d201b 100644 --- a/test/src/index.test.js +++ b/test/src/index.test.js @@ -8,6 +8,7 @@ describe('worker', () => { it('should be an instance of Worker', () => { worker = new Worker(); + // eslint-disable-next-line jest/no-jasmine-globals expect(worker).toEqual(jasmine.any(window.Worker)); }); @@ -15,6 +16,25 @@ describe('worker', () => { expect(await worker.foo()).toBe(1); }); + it('worker.otherFoo()', async () => { + expect(await worker.otherFoo()).toBe(-1); + }); + + it('worker.otherOtherFoo()', async () => { + expect(await worker.otherOtherFoo()).toBe(2); + }); + it('worker.andTheOtherFoo()', async () => { + expect(await worker.andTheOtherFoo()).toBe(2); + }); + + it('worker.anyFoo()', async () => { + expect(await worker.anyFoo()).toBe(4); + }); + + it('worker.tragedy()', async () => { + expect(await worker.tragedy()).toBe('common'); + }); + it('worker.bar()', async () => { let out = await worker.bar('a', 'b'); expect(out).toEqual('a [bar:3] b'); @@ -102,6 +122,7 @@ describe('?import option', () => { it('should be an instance of Worker', () => { worker = new ImportWorker(); + // eslint-disable-next-line jest/no-jasmine-globals expect(worker).toEqual(jasmine.any(window.Worker)); }); diff --git a/test/src/other.js b/test/src/other.js index f4fbc35..8a2402b 100644 --- a/test/src/other.js +++ b/test/src/other.js @@ -1,3 +1,5 @@ -export function otherFoo() {} +export function otherFoo() { + return -1; +} -export const otherBar = 3; \ No newline at end of file +export const otherBar = 3; diff --git a/test/src/worker.js b/test/src/worker.js index 73b1049..1751c3c 100644 --- a/test/src/worker.js +++ b/test/src/worker.js @@ -1,11 +1,17 @@ import { otherFoo, otherBar } from './other'; export { otherFoo }; +export { otherOtherFoo as andTheOtherFoo } from './and-the-other'; +export * from './and-the-other'; + +export { tragedy } from './common.js'; export function foo() { return 1; } +export const value = 3; + export function throwError() { throw new Error('Error in worker.js'); }