Skip to content

Commit

Permalink
Merge pull request #1198 from typed-ember/test-race-condition
Browse files Browse the repository at this point in the history
fix(typecheck-worker): avoid false-positive `willTypecheck`s on Linux
  • Loading branch information
dfreeman committed Jul 3, 2020
2 parents 1077e51 + b7f2f92 commit 8162cb1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions ts/lib/typechecking/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class TypecheckWorker {
private patchCompilerHostMethods(
host: WatchCompilerHostOfConfigFile<SemanticDiagnosticsBuilderProgram>
) {
let { watchFile, watchDirectory, createProgram, afterProgramCreate = () => {} } = host;
let { watchFile, watchDirectory, afterProgramCreate = () => {} } = host;

// Intercept tsc's `watchFile` to also invoke `mayTypecheck()` when a watched file changes
host.watchFile = (path, callback, pollingInterval?) => {
Expand Down Expand Up @@ -167,14 +167,11 @@ export default class TypecheckWorker {
);
};

// Intercept `createProgram` to invoke `willTypecheck` beforehand, as we know at this
// point that a new check is definitively happening.
host.createProgram = (...params) => {
// Intercept `afterProgramCreate` to confirm when a suspected typecheck is happening
// and schedule the new diagnostics to be emitted.
host.afterProgramCreate = (program) => {
this.willTypecheck();
return createProgram.apply(host, params);
};

host.afterProgramCreate = (program) => {
// The `afterProgramCreate` callback will be invoked synchronously when we first call
// `createWatchProgram`, meaning we can enter `didTypecheck` before we're fully set up
// (e.g. before `compilerOptions` has been set). We use `nextTick` to ensure that
Expand Down
2 changes: 1 addition & 1 deletion ts/tests/helpers/skeleton-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getEmberPort = (() => {
export default class SkeletonApp {
port = getEmberPort();
watched: WatchedBuild | null = null;
cleanupTempDir = () => rimraf(this.root, (error) => console.error(error));
cleanupTempDir = () => rimraf(this.root, (error) => error && console.error(error));
root = path.join(process.cwd(), `test-skeleton-app-${Math.random().toString(36).slice(2)}`);

constructor() {
Expand Down

0 comments on commit 8162cb1

Please sign in to comment.