Skip to content

Commit dd9a1c2

Browse files
authored
Add --location flag support (#47)
1 parent 4fac012 commit dd9a1c2

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.github/workflows/continuous-integration-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
os: [ubuntu-latest, macOS-latest, windows-latest]
1111
node-version: [12.x]
12-
deno-version: [1.x]
12+
deno-version: [1.40.x]
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- uses: actions/checkout@v1

src/DenoWorker.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,46 @@ describe('DenoWorker', () => {
307307
});
308308
});
309309

310+
describe('location', async () => {
311+
afterEach(() => {
312+
jest.clearAllMocks();
313+
});
314+
315+
it('supports the --location flag to specify location.href', async () => {
316+
const spawnSpy = jest.spyOn(child_process, 'spawn');
317+
const LOCATION = 'https://xxx.com/';
318+
319+
worker = new DenoWorker(
320+
`self.onmessage = (e) => {
321+
if (e.data.type === 'echo') {
322+
self.postMessage(location.href);
323+
}
324+
};`,
325+
{
326+
location: LOCATION,
327+
}
328+
);
329+
330+
let resolve: any;
331+
let promise = new Promise((res, rej) => {
332+
resolve = res;
333+
});
334+
worker.onmessage = (e) => {
335+
resolve(e);
336+
};
337+
338+
worker.postMessage({
339+
type: 'echo',
340+
});
341+
342+
expect(await promise).toEqual({ data: LOCATION });
343+
344+
const call = spawnSpy.mock.calls[0];
345+
const [_deno, args] = call;
346+
expect(args).toContain(`--location=${LOCATION}`);
347+
});
348+
});
349+
310350
describe('denoCachedOnly', async () => {
311351
afterEach(() => {
312352
jest.clearAllMocks();

src/DenoWorker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ export interface DenoWorkerOptions {
159159
*/
160160
denoNoCheck: boolean;
161161

162+
/**
163+
* Specify the --location flag, which defines location.href.
164+
* This must be a valid URL if provided.
165+
*/
166+
location: string;
167+
162168
/**
163169
* The permissions that the Deno worker should use.
164170
*/
@@ -274,6 +280,7 @@ export class DenoWorker {
274280
logStdout: true,
275281
logStderr: true,
276282
denoUnstable: false,
283+
location: undefined,
277284
permissions: {},
278285
denoV8Flags: [],
279286
denoImportMapPath: '',
@@ -391,6 +398,9 @@ export class DenoWorker {
391398
}
392399
addOption(runArgs, '--cached-only', this._options.denoCachedOnly);
393400
addOption(runArgs, '--no-check', this._options.denoNoCheck);
401+
if (this._options.location) {
402+
addOption(runArgs, '--location', [this._options.location]);
403+
}
394404

395405
if (this._options.denoV8Flags.length > 0) {
396406
addOption(runArgs, '--v8-flags', this._options.denoV8Flags);

0 commit comments

Comments
 (0)