Skip to content

Commit

Permalink
fix subprocess in windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Oct 6, 2023
1 parent e0a9dc7 commit 38643b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
7 changes: 4 additions & 3 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion tests/scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"ember-source-beta": "npm:ember-source@beta",
"ember-source-latest": "npm:ember-source@latest",
"ember-truth-helpers": "^3.0.0",
"execa": "^4.0.3",
"execa": "^5.1.1",
"tslib": "^2.6.0",
"typescript": "^5.1.6"
},
Expand Down
39 changes: 22 additions & 17 deletions tests/scenarios/watch-mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import globby from 'globby';
import fs from 'fs/promises';
import path from 'path';
import execa from 'execa';

const { module: Qmodule, test } = QUnit;

let app = appScenarios.map('watch-mode', () => {
Expand All @@ -18,8 +19,17 @@ app.forEachScenario(scenario => {
Qmodule(scenario.name, function (hooks) {
let app: PreparedApp;
let watchProcess: ReturnType<any>;
let startedPromise: Promise<void>;
let waitFor: (stdoutContent: string) => Promise<void>;

function waitFor(stdoutContent: string) {
return new Promise<void>((resolve) => {
watchProcess.stdout.on('data', (data: Buffer) => {
let str = data.toString();
if (str.includes(stdoutContent)) {
resolve();
}
});
});
};

async function checkScripts(distPattern: RegExp, needle: string) {
let root = app.dir;
Expand All @@ -37,27 +47,22 @@ app.forEachScenario(scenario => {
hooks.beforeEach(async () => {
app = await scenario.prepare();
watchProcess = execa('ember', ['s'], { cwd: app.dir });

waitFor = (stdoutContent: string) => {
return new Promise<void>(resolve => {
watchProcess.stdout.on('data', (data: Buffer) => {
let str = data.toString();
if (str.includes(stdoutContent)) {
resolve();
}
});
});
};

startedPromise = waitFor('Serving on');
});

hooks.afterEach(async () => {
watchProcess.cancel();
watchProcess.kill();

// on windows the subprocess won't close if you don't end all the sockets
// we don't just end stdout because when you register a listener for stdout it auto registers stdin and stderr... for some reason :(
watchProcess.stdio.forEach((socket: any) => {
if (socket) {
socket.end();
}
});
});

test(`pnpm ember test`, async function (assert) {
await startedPromise;
await waitFor('Serving on');
const content = 'TWO IS A GREAT NUMBER< I LKE IT A LOT< IT IS THE POWER OF ALL OF ELECTRONICS, MATH, ETC';

assert.false(await checkScripts(/js$/, content), 'file has not been created yet');
Expand Down

0 comments on commit 38643b5

Please sign in to comment.