Skip to content

Commit

Permalink
Update obvious write-then-watch patterns to use writeAndAwaitOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman committed Nov 14, 2023
1 parent 643387b commit 0fd69f6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 47 deletions.
20 changes: 11 additions & 9 deletions packages/core/__tests__/cli/build-watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ describe('CLI: watched build mode typechecking', () => {

await pauseForTSBuffering();

project.write(INPUT_SFC, code.replace('this.startupTime', 'this.startupTimee'));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
INPUT_SFC,
code.replace('this.startupTime', 'this.startupTimee'),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

await pauseForTSBuffering();

project.write(INPUT_SFC, code);

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(INPUT_SFC, code, 'Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

await watch.terminate();
Expand Down Expand Up @@ -237,9 +237,11 @@ describe('CLI: watched build mode typechecking', () => {

await pauseForTSBuffering();

project.write(INPUT_SFC, code.replace('{{! @glint-nocheck }}', ''));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
INPUT_SFC,
code.replace('{{! @glint-nocheck }}', ''),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

await watch.terminate();
Expand Down
11 changes: 6 additions & 5 deletions packages/core/__tests__/cli/custom-extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ describe('CLI: custom extensions', () => {
"Cannot find module './other' or its corresponding type declarations."
);

project.write('other.gjs', 'export const foo = 123;');

await watch.awaitOutput('Found 0 errors.');
await watch.writeAndAwaitOutput('other.gjs', 'export const foo = 123;', 'Found 0 errors.');
await watch.terminate();
});

Expand All @@ -95,8 +93,11 @@ describe('CLI: custom extensions', () => {

expect(output).toMatch('Found 0 errors.');

project.write('other.gjs', 'export const foo = "hi";');
output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'other.gjs',
'export const foo = "hi";',
'Watching for file changes.'
);

expect(output).toMatch('Found 1 error.');
expect(output).toMatch('TS2362');
Expand Down
76 changes: 43 additions & 33 deletions packages/core/__tests__/cli/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ describe('CLI: watched typechecking', () => {
let output = await watch.awaitOutput('Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

project.write('index.ts', code.replace('this.startupTime', 'this.startupTimee'));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'index.ts',
code.replace('this.startupTime', 'this.startupTimee'),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

project.write('index.ts', code);

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput('index.ts', code, 'Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

expect(watch.allOutput).toMatch(/\033c/); // output should include screen reset control sequence
Expand Down Expand Up @@ -196,19 +196,25 @@ describe('CLI: watched typechecking', () => {
let output = await watch.awaitOutput('Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

project.write('my-component.hbs', template.replace('target', 'tarrget'));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'my-component.hbs',
template.replace('target', 'tarrget'),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

project.write('my-component.hbs', template);

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'my-component.hbs',
template,
'Watching for file changes.'
);
expect(output).toMatch('Found 0 errors.');

project.write('my-component.hbs', template.replace('@message', '@messagee'));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'my-component.hbs',
template.replace('@message', '@messagee'),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

project.remove('my-component.hbs');
Expand Down Expand Up @@ -238,14 +244,14 @@ describe('CLI: watched typechecking', () => {
let output = await watch.awaitOutput('Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

project.write('index.gts', code.replace('this.startupTime', 'this.startupTimee'));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'index.gts',
code.replace('this.startupTime', 'this.startupTimee'),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

project.write('index.gts', code);

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput('index.gts', code, 'Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

await watch.terminate();
Expand Down Expand Up @@ -278,14 +284,18 @@ describe('CLI: watched typechecking', () => {
let output = await watch.awaitOutput('Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

project.write('my-component.ts', script.replace('// ', ''));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'my-component.ts',
script.replace('// ', ''),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

project.write('my-component.ts', script);

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'my-component.ts',
script,
'Watching for file changes.'
);
expect(output).toMatch('Found 0 errors.');

await watch.terminate();
Expand Down Expand Up @@ -316,14 +326,14 @@ describe('CLI: watched typechecking', () => {
let output = await watch.awaitOutput('Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

project.write('index.ts', code.replace('this.startupTime', 'this.startupTimee'));

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput(
'index.ts',
code.replace('this.startupTime', 'this.startupTimee'),
'Watching for file changes.'
);
expect(output).toMatch('Found 1 error.');

project.write('index.ts', code);

output = await watch.awaitOutput('Watching for file changes.');
output = await watch.writeAndAwaitOutput('index.ts', code, 'Watching for file changes.');
expect(output).toMatch('Found 0 errors.');

expect(watch.allOutput).not.toMatch(/\033c/); // output should not include screen reset control sequence
Expand Down

0 comments on commit 0fd69f6

Please sign in to comment.