Skip to content

Commit bc28d5a

Browse files
authored
Merge pull request #9 from derekwheel/deno_worker_unstable
add denoUnstable flag to DenoWorkerOptions
2 parents 4255dfb + 09c97b3 commit bc28d5a

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

src/DenoWorker.spec.ts

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
import { URL } from 'url';
55
import { MessageChannel, MessagePort } from './MessageChannel';
66
import psList from 'ps-list';
7+
import child_process from 'child_process';
78

89
console.log = jest.fn();
910
jest.setTimeout(10000);
@@ -112,6 +113,87 @@ describe('DenoWorker', () => {
112113
message: 'Hello',
113114
});
114115
});
116+
117+
describe('denoUnstable', async () => {
118+
afterEach(() => {
119+
jest.clearAllMocks();
120+
});
121+
122+
it('should not include the --unstable flag by default', async () => {
123+
const spawnSpy = jest.spyOn(child_process, 'spawn');
124+
125+
worker = new DenoWorker(echoScript);
126+
127+
let resolve: any;
128+
let promise = new Promise((res, rej) => {
129+
resolve = res;
130+
});
131+
worker.onmessage = (e) => {
132+
resolve();
133+
};
134+
135+
worker.postMessage({
136+
type: 'echo',
137+
message: 'Hello',
138+
});
139+
140+
await promise;
141+
142+
const call = spawnSpy.mock.calls[0];
143+
const [_deno, args] = call;
144+
expect(args).not.toContain('--unstable');
145+
});
146+
147+
it('should not include the --unstable flag by when denoUnstable is false', async () => {
148+
const spawnSpy = jest.spyOn(child_process, 'spawn');
149+
150+
worker = new DenoWorker(echoScript, { denoUnstable: false });
151+
152+
let resolve: any;
153+
let promise = new Promise((res, rej) => {
154+
resolve = res;
155+
});
156+
worker.onmessage = (e) => {
157+
resolve();
158+
};
159+
160+
worker.postMessage({
161+
type: 'echo',
162+
message: 'Hello',
163+
});
164+
165+
await promise;
166+
167+
const call = spawnSpy.mock.calls[0];
168+
const [_deno, args] = call;
169+
expect(args).not.toContain('--unstable');
170+
});
171+
172+
it('should allow include the --unstable flag when denoUnstable is true', async () => {
173+
const spawnSpy = jest.spyOn(child_process, 'spawn');
174+
175+
worker = new DenoWorker(echoScript, { denoUnstable: true });
176+
177+
let resolve: any;
178+
let promise = new Promise((res, rej) => {
179+
resolve = res;
180+
});
181+
worker.onmessage = (e) => {
182+
resolve();
183+
};
184+
185+
worker.postMessage({
186+
type: 'echo',
187+
message: 'Hello',
188+
});
189+
190+
await promise;
191+
192+
const call = spawnSpy.mock.calls[0];
193+
const [_deno, args] = call;
194+
expect(args).toContain('--unstable');
195+
});
196+
});
115197
});
116198

117199
describe('data types', () => {
@@ -440,6 +522,8 @@ describe('DenoWorker', () => {
440522

441523
async function getDenoProcesses() {
442524
const list = await psList();
443-
const denoProcesses = list.filter((p) => /^deno/.test(p.name));
525+
const denoProcesses = list.filter(
526+
(p) => /^deno/.test(p.name) && p.cmd !== 'deno lsp'
527+
);
444528
return denoProcesses;
445529
}

src/DenoWorker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export interface DenoWorkerOptions {
5555
*/
5656
logStderr: boolean;
5757

58+
/**
59+
* Whether to use Deno's unstable features
60+
*/
61+
denoUnstable: boolean;
62+
5863
/**
5964
* The permissions that the Deno worker should use.
6065
*/
@@ -152,6 +157,7 @@ export class DenoWorker {
152157
reload: process.env.NODE_ENV !== 'production',
153158
logStdout: true,
154159
logStderr: true,
160+
denoUnstable: false,
155161
permissions: {},
156162
},
157163
options || {}
@@ -242,7 +248,7 @@ export class DenoWorker {
242248
let runArgs = [] as string[];
243249

244250
addOption(runArgs, '--reload', this._options.reload);
245-
// addOption(runArgs, '--unstable', true);
251+
addOption(runArgs, '--unstable', this._options.denoUnstable);
246252

247253
if (this._options.permissions) {
248254
addOption(

0 commit comments

Comments
 (0)