-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests and refactored code (Part 1) #3
Conversation
… files and simplified the test setup.
throw new SyntaxError( | ||
'ERROR: In package.json, the package name is missing.' | ||
); | ||
} | ||
|
||
if (!addonPackage.version) { | ||
throw new SyntaxError( | ||
'ERROR: In package.json, the package version is missing.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to npm
, we can expect that a valid package.json
will always have the name
and version
fields.
https://docs.npmjs.com/creating-a-package-json-file#required-name-and-version-fields
packagesToDelete.forEach((packageName) => { | ||
devDependencies.delete(packageName); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused code. To be precise, a no-op because devDependencies
becomes an empty map after line 69.
packageJson['keywords'] = (packageJson['keywords'] ?? []).filter( | ||
(keyword) => keyword !== 'ember-addon' | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package.json
in an Ember addon should have the keywords
field, which is an array that includes 'ember-addon'
. Just in case, I used the nullish coalescing operator to prevent a runtime error.
@@ -10,8 +10,8 @@ test('migration | ember-addon | steps | augment-options > error handling (corrup | |||
}; | |||
|
|||
const inputProject = { | |||
'package.json': '{\n name:}', | |||
'yarn.lock': 'some code for yarn.lock', | |||
'package.json': '{\n "name": }', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to test what would happen when the value is missing.
Instead, I had incorrectly tested the case of a JSON key having an incorrect format (because the double quotations are missing).
` Features,`, | ||
` IndexSignatureParameter,`, | ||
` QueryResults,`, | ||
`} from '../modifiers/container-query';`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we're asserting that useRelativePaths
...
- Switches Ember's "magic" import path,
ember-container-query/modifiers/container-query
, to JavaScript's relative path,../modifiers/container-query
- Does not alter the rest of the file
`import type { Image } from '../../../../data/concert';`, | ||
`import { findBestFittingImage } from '../../../../utils/components/widgets/widget-3';`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we're asserting that useRelativePaths
...
- Finds and replaces multiple "magic" paths in a given file
|
||
output: [ | ||
`import Application from '@ember/application';`, | ||
`import config from './config/environment';`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we're asserting that useRelativePaths
...
-
Normalizes the relative path, i.e. if the referenced file is in the same directory as the file that is about to be modified, then the path should be prefixed with
./
.In other words, we should not be seeing the line
import config from 'config/environment';
, because this implies there is a package namedconfig
.
Description
Currently, we assert at an "acceptance" level that
ember-codemod-v1-to-v2
can run all steps without encountering an error. However, there are no "integration" tests that explain the output of each step. Such tests would help contributors (including myself in the future) understand the codebase.I'll create a series of pull requests to incrementally add tests for each step. In this pull request, tests for the following steps have been added:
augmentOptions
analyzeAddon
useRelativePaths