Skip to content

Commit 4b914f8

Browse files
committed
Allow for case where we don't need to move package
1 parent c265d74 commit 4b914f8

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

ts/tests/blueprints/ember-cli-typescript-test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'path';
55
import helpers from 'ember-cli-blueprint-test-helpers/helpers';
66
import chaiHelpers from 'ember-cli-blueprint-test-helpers/chai';
77
import Blueprint from 'ember-cli/lib/models/blueprint';
8+
import ts from 'typescript';
89

910
import { setupPublishedVersionStashing } from '../helpers/stash-published-version';
1011
import ects from '../../blueprints/ember-cli-typescript/index';
@@ -71,7 +72,7 @@ describe('Acceptance: ember-cli-typescript generator', function () {
7172
const tsconfig = file('tsconfig.json');
7273
expect(tsconfig).to.exist;
7374

74-
const tsconfigJson = JSON.parse(tsconfig.content);
75+
const tsconfigJson = ts.parseConfigFileTextToJson('tsconfig.json', tsconfig.content).config;
7576
expect(tsconfigJson.compilerOptions.paths).to.deep.equal({
7677
'my-app/tests/*': ['tests/*'],
7778
'my-app/*': ['app/*'],
@@ -121,7 +122,7 @@ describe('Acceptance: ember-cli-typescript generator', function () {
121122
const tsconfig = file('tsconfig.json');
122123
expect(tsconfig).to.exist;
123124

124-
const tsconfigJson = JSON.parse(tsconfig.content);
125+
const tsconfigJson = ts.parseConfigFileTextToJson('tsconfig.json', tsconfig.content).config;
125126
expect(tsconfigJson.compilerOptions.paths).to.deep.equal({
126127
'dummy/tests/*': ['tests/*'],
127128
'dummy/*': ['tests/dummy/app/*', 'app/*'],
@@ -197,7 +198,7 @@ describe('Acceptance: ember-cli-typescript generator', function () {
197198
const tsconfig = file('tsconfig.json');
198199
expect(tsconfig).to.exist;
199200

200-
const json = JSON.parse(tsconfig.content);
201+
const json = ts.parseConfigFileTextToJson('tsconfig.json', tsconfig.content).config;
201202
expect(json.compilerOptions.paths).to.deep.equal({
202203
'my-app/tests/*': ['tests/*'],
203204
'my-app/*': ['app/*', 'lib/my-addon-1/app/*', 'lib/my-addon-2/app/*'],
@@ -243,7 +244,7 @@ describe('Acceptance: ember-cli-typescript generator', function () {
243244
const tsconfig = file('tsconfig.json');
244245
expect(tsconfig).to.exist;
245246

246-
const json = JSON.parse(tsconfig.content);
247+
const json = ts.parseConfigFileTextToJson('tsconfig.json', tsconfig.content).config;
247248
expect(json.compilerOptions.paths).to.deep.equal({
248249
'my-app/tests/*': ['tests/*'],
249250
'my-app/mirage/*': ['mirage/*'],
@@ -269,7 +270,7 @@ describe('Acceptance: ember-cli-typescript generator', function () {
269270
const tsconfig = file('tsconfig.json');
270271
expect(tsconfig).to.exist;
271272

272-
const json = JSON.parse(tsconfig.content);
273+
const json = ts.parseConfigFileTextToJson('tsconfig.json', tsconfig.content).config;
273274
expect(json.compilerOptions.paths).to.deep.equal({
274275
'dummy/tests/*': ['tests/*'],
275276
'dummy/mirage/*': ['tests/dummy/mirage/*'],

ts/tests/helpers/stash-published-version.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import fs from 'fs-extra';
22

33
const PACKAGE_PATH = 'node_modules/ember-cli-typescript';
44

5+
function isNodeError(e: unknown): e is NodeJS.ErrnoException {
6+
// Not full-proof but good enough for our purposes.
7+
return e instanceof Error && 'code' in e;
8+
}
9+
10+
function handleError(e: unknown) {
11+
// Ignore the case where we just don't have the files to move. (And hope this
12+
// works correctly?)
13+
if (!isNodeError(e) || e.code !== 'ENOENT') {
14+
throw e;
15+
}
16+
}
17+
518
/**
619
* We have assorted devDependencies that themselves depend on `ember-cli-typescript`.
720
* This means we have a published copy of the addon present in `node_modules` normally,
@@ -12,10 +25,19 @@ const PACKAGE_PATH = 'node_modules/ember-cli-typescript';
1225
*/
1326
export function setupPublishedVersionStashing(hooks: Mocha.Suite): void {
1427
hooks.beforeAll(async () => {
15-
await fs.move(PACKAGE_PATH, `${PACKAGE_PATH}.published`);
28+
fs.move(PACKAGE_PATH, `${PACKAGE_PATH}.published`).catch();
29+
try {
30+
await fs.move(PACKAGE_PATH, `${PACKAGE_PATH}.published`);
31+
} catch (e: unknown) {
32+
handleError(e);
33+
}
1634
});
1735

1836
hooks.afterAll(async () => {
19-
await fs.move(`${PACKAGE_PATH}.published`, PACKAGE_PATH);
37+
try {
38+
await fs.move(`${PACKAGE_PATH}.published`, PACKAGE_PATH);
39+
} catch (e) {
40+
handleError(e);
41+
}
2042
});
2143
}

0 commit comments

Comments
 (0)