Skip to content

Commit 55d7738

Browse files
author
Tim Lindvall
committed
test: Delete some cached files in tests.
This change ensures that the precompile tests that exercise package naming properly read package.json and index.js from disk. This makes it so the test fails without the moduleName() fix in the prior commit.
1 parent ee0b9fd commit 55d7738

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ts/tests/commands/precompile-test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs-extra';
2+
import * as path from 'path';
23
import { hook } from 'capture-console';
34
import ember from 'ember-cli-blueprint-test-helpers/lib/helpers/ember';
45
import blueprintHelpers from 'ember-cli-blueprint-test-helpers/helpers';
@@ -109,6 +110,13 @@ describe('Acceptance: ts:precompile command', function () {
109110
pkg.name = '@foo/my-addon'; // addon `name` is `my-addon`
110111
fs.writeJSONSync('package.json', pkg);
111112

113+
// CAUTION! HACKY CODE AHEAD!
114+
// The ember blueprint helper stays in the same node process, so require
115+
// keeps any previously read files cached. We need to clear out these
116+
// caches so it picks up the changes properly.
117+
delete require.cache[path.join(process.cwd(), 'index.js')];
118+
delete require.cache[path.join(process.cwd(), 'package.json')];
119+
112120
return ember(['ts:precompile']).then(() => {
113121
const declaration = file('test-support/test-file.d.ts');
114122
expect(declaration).to.exist;
@@ -136,6 +144,13 @@ describe('Acceptance: ts:precompile command', function () {
136144
pkg.name = '@foo/my-addon'; // addon `moduleName()` is `my-addon`
137145
fs.writeJSONSync('package.json', pkg);
138146

147+
// CAUTION! HACKY CODE AHEAD!
148+
// The ember blueprint helper stays in the same node process, so require
149+
// keeps any previously read files cached. We need to clear out these
150+
// caches so it picks up the changes properly.
151+
delete require.cache[path.join(process.cwd(), 'index.js')];
152+
delete require.cache[path.join(process.cwd(), 'package.json')];
153+
139154
return ember(['ts:precompile']).then(() => {
140155
const componentDecl = file('components/my-component.d.ts');
141156
expect(componentDecl).to.exist;

0 commit comments

Comments
 (0)