Skip to content

Commit cf992bc

Browse files
authored
Added tests and refactored code (Part 2) (#4)
* refactor: Practiced a better separation of concerns * refactor: Practiced early exit * chore: Renamed test file * chore: Moved the fixture-helpers file to the tests/helpers folder * chore: Moved the test-helpers file to the tests/helpers folder * chore: Created test setups that can be shared among the tests for each step * refactor: Updated tests for analyzeAddon * refactor: Updated tests for useRelativePaths * refactor: Added tests for moveAddonFiles Co-authored-by: ijlee2 <[email protected]>
1 parent eee5a79 commit cf992bc

File tree

54 files changed

+947
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+947
-151
lines changed

create-test-fixture.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fi
5151
mkdir -p "tests/fixtures/$DESTINATION/input"
5252
mkdir -p "tests/fixtures/$DESTINATION/output"
5353

54-
echo "import { convertToJson } from '../../fixture-helpers.js';
54+
echo "import { convertToJson } from '../../helpers/fixture.js';
5555
5656
const inputProject = convertToJson('$DESTINATION/input');
5757
const outputProject = convertToJson('$DESTINATION/output');

src/migration/ember-addon/steps/augment-options.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ function analyzePackageJson(options) {
2020
version,
2121
} = JSON.parse(packageJsonFile);
2222

23+
if (!name) {
24+
throw new SyntaxError('Package name is missing.');
25+
}
26+
27+
if (!version) {
28+
throw new SyntaxError('Package version is missing.');
29+
}
30+
2331
const projectDependencies = new Map([
2432
...Object.entries(dependencies ?? {}),
2533
...Object.entries(devDependencies ?? {}),
@@ -35,7 +43,7 @@ function analyzePackageJson(options) {
3543
};
3644
} catch (e) {
3745
throw new SyntaxError(
38-
`ERROR: package.json is missing or is not a valid JSON. (${e.message})\n`
46+
`ERROR: package.json is missing or is not valid. (${e.message})\n`
3947
);
4048
}
4149
}
@@ -67,33 +75,21 @@ function analyzePackageManager(options) {
6775
}
6876

6977
function deriveAddonLocation(addonPackage) {
70-
if (!addonPackage.name) {
71-
throw new SyntaxError(
72-
'ERROR: In package.json, the package name is missing.'
73-
);
78+
// Package is not scoped
79+
if (!addonPackage.name.includes('/')) {
80+
return addonPackage.name;
7481
}
7582

76-
if (!addonPackage.version) {
83+
// eslint-disable-next-line no-unused-vars
84+
const [scope, packageName] = addonPackage.name.split('/');
85+
86+
if (!packageName) {
7787
throw new SyntaxError(
78-
'ERROR: In package.json, the package version is missing.'
88+
`ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
7989
);
8090
}
8191

82-
// Package is scoped
83-
if (addonPackage.name.includes('/')) {
84-
// eslint-disable-next-line no-unused-vars
85-
const [scope, packageName] = addonPackage.name.split('/');
86-
87-
if (!packageName) {
88-
throw new SyntaxError(
89-
`ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
90-
);
91-
}
92-
93-
return packageName;
94-
}
95-
96-
return addonPackage.name;
92+
return packageName;
9793
}
9894

9995
export function augmentOptions(options) {

tests/fixtures/ember-container-query-customizations/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('ember-container-query-customizations/input');
44
const outputProject = convertToJson('ember-container-query-customizations/output');

tests/fixtures/ember-container-query-javascript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('ember-container-query-javascript/input');
44
const outputProject = convertToJson('ember-container-query-javascript/output');

tests/fixtures/ember-container-query-typescript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('ember-container-query-typescript/input');
44
const outputProject = convertToJson('ember-container-query-typescript/output');

tests/fixtures/new-v1-addon-customizations/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('new-v1-addon-customizations/input');
44
const outputProject = convertToJson('new-v1-addon-customizations/output');

tests/fixtures/new-v1-addon-javascript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('new-v1-addon-javascript/input');
44
const outputProject = convertToJson('new-v1-addon-javascript/output');

tests/fixtures/new-v1-addon-npm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('new-v1-addon-npm/input');
44
const outputProject = convertToJson('new-v1-addon-npm/output');

tests/fixtures/new-v1-addon-pnpm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('new-v1-addon-pnpm/input');
44
const outputProject = convertToJson('new-v1-addon-pnpm/output');

tests/fixtures/new-v1-addon-typescript/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertToJson } from '../../fixture-helpers.js';
1+
import { convertToJson } from '../../helpers/fixture.js';
22

33
const inputProject = convertToJson('new-v1-addon-typescript/input');
44
const outputProject = convertToJson('new-v1-addon-typescript/output');

0 commit comments

Comments
 (0)