Skip to content

Commit

Permalink
Refactored promises to avoid possible fs stream concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Jul 12, 2019
1 parent a560aa0 commit f11847a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/jest-core/src/__tests__/watch-file-changes.test.ts
Expand Up @@ -35,6 +35,8 @@ describe('Watch mode flows with changed files', () => {
watch = require('../watch').default;
pipe = {write: jest.fn()} as any;
stdin = new MockStdin();
rimraf.sync(cacheDirectory);
rimraf.sync(testDirectory);
fs.mkdirSync(testDirectory);
fs.mkdirSync(cacheDirectory);
});
Expand All @@ -44,11 +46,6 @@ describe('Watch mode flows with changed files', () => {
if (hasteMapInstance) {
hasteMapInstance.end();
}
[fileTargetPath2, fileTargetPath].forEach(file => {
try {
fs.unlinkSync(file);
} catch (e) {}
});
rimraf.sync(cacheDirectory);
rimraf.sync(testDirectory);
});
Expand Down Expand Up @@ -121,7 +118,7 @@ describe('Watch mode flows with changed files', () => {
hook,
);

await new Promise(resolve => {
const successPromise: Promise<AggregatedResult> = new Promise(resolve => {
hook.getSubscriber().onTestRunComplete(resolve);
});

Expand All @@ -138,9 +135,7 @@ describe('Watch mode flows with changed files', () => {
{encoding: 'utf-8'},
);

const resultSuccessReport: AggregatedResult = await new Promise(resolve => {
hook.getSubscriber().onTestRunComplete(resolve);
});
const resultSuccessReport: AggregatedResult = await successPromise;

expect(resultSuccessReport).toMatchObject({
numFailedTestSuites: 0,
Expand All @@ -154,12 +149,14 @@ describe('Watch mode flows with changed files', () => {
failureMessage: null,
});

const errorPromise: Promise<AggregatedResult> = new Promise(resolve => {
hook.getSubscriber().onTestRunComplete(resolve);
});

// Remove again to ensure about no legacy cache
fs.unlinkSync(fileTargetPath);

const resultErrorReport: AggregatedResult = await new Promise(resolve => {
hook.getSubscriber().onTestRunComplete(resolve);
});
const resultErrorReport: AggregatedResult = await errorPromise;

// After remove file we have to fail tests
expect(resultErrorReport).toMatchObject({
Expand Down

0 comments on commit f11847a

Please sign in to comment.