Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ Configuration is optional. It should be put in a file at `config/coverage.js` (`

- `parallel`: Defaults to `false`. Should be set to true if parallel testing is being used for separate test runs, for example when using [ember-exam](https://github.com/trentmwillis/ember-exam) with the `--partition` flag. This will generate the coverage reports in directories suffixed with `_<random_string>` to avoid overwriting other threads reports. These reports can be joined by using the `ember coverage-merge` command (potentially as part of the [posttest hook](https://docs.npmjs.com/misc/scripts) in your `package.json`).

- `modifyAssetLocation`: Optional function that will allow you to override where a file actually lives inside of your project. See [Advanced customization](#modifyassetlocation) on how to use this function in practice.

#### Example
```js
module.exports = {
Expand Down Expand Up @@ -190,7 +192,9 @@ If you are using [`ember-cli-pretender`](https://github.com/rwjblue/ember-cli-pr

## Advanced customization

The `forceModulesToBeLoaded` can potientally cause unindented side effects when executed. You can pass custom filter fuctions that allow
### `forceModulesToBeLoaded`

The `forceModulesToBeLoaded` function can potentially cause unintended side effects when executed. You can pass custom filter fuctions that allow
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some typos here while I was at it

you to specify which modules will be force loaded or not:

```js
Expand All @@ -201,28 +205,28 @@ QUnit.done(async () => {
});
```

### `modifyAssetLocation`

Under the hood, `ember-cli-code-coverage` attempts to "de-namespacify" paths into their real on disk location inside of
`project.root` (ie give a namespaced path like lib/inrepo/components/foo.js would live in lib/inrepo/addon/components/foo.js). It makes
some assumptions (where files live in in-repo addons vs app code for example) and sometimes those assumptions might not hold. Passing a
function `modifyAssetLocation` will allow you to override where a file actually lives inside of your project. The returned string should
be relative to your project root.
function `modifyAssetLocation` in your [configuration file](#configuration) will allow you to override where a file actually lives inside
of your project. The returned string should be relative to your project root.

```js
const app = new EmberApp(defaults, {
'ember-cli-code-coverage': {
modifyAssetLocation(root, relativePath) {
let appPath = relativePath.replace('my-project-name', 'app');

// here is an example of saying that `app/components/foo.js` actually
// lives in `lib/inrepo/app/components/foo.js` on disk.
if (fs.existsSync(path.join(root, 'lib/inrepo', appPath))) {
return path.join('lib/inrepo', appPath);
}

return false;
},
module.exports = {
modifyAssetLocation(root, relativePath) {
let appPath = relativePath.replace('my-project-name', 'app');

// here is an example of saying that `app/components/foo.js` actually
// lives in `lib/inrepo/app/components/foo.js` on disk.
if (fs.existsSync(path.join(root, 'lib', 'inrepo', appPath))) {
return path.join('lib', 'inrepo', appPath);
}

return false;
},
});
};
```

## Inspiration
Expand Down
10 changes: 0 additions & 10 deletions packages/ember-cli-code-coverage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ module.exports = {
};
},

included(app) {
this._super.included.apply(this, arguments);
let config = app.options[this.name] || {};
this.modifyAssetLocation = config && config.modifyAssetLocation;
},

buildNamespaceMappings() {
let rootNamespaceMappings = new Map();
function recurse(item) {
Expand Down Expand Up @@ -124,19 +118,15 @@ module.exports = {
attachMiddleware.serverMiddleware(startOptions.app, {
configPath: this.project.configPath(),
root: this.project.root,
fileLookup: this.fileLookup,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this as well, as this is a leftover from the 1.0 version

namespaceMappings: this.buildNamespaceMappings(),
modifyAssetLocation: this.modifyAssetLocation,
});
},

testemMiddleware(app) {
const config = {
configPath: this.project.configPath(),
root: this.project.root,
fileLookup: this.fileLookup,
namespaceMappings: this.buildNamespaceMappings(),
modifyAssetLocation: this.modifyAssetLocation,
};
// if we're running `ember test --server` use the `serverMiddleware`.
if (process.argv.includes('--server') || process.argv.includes('-s')) {
Expand Down
4 changes: 3 additions & 1 deletion packages/ember-cli-code-coverage/lib/attach-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ function adjustCoverageKey(
}

function adjustCoverage(coverage, options) {
let { root, namespaceMappings, modifyAssetLocation } = options;
let { root, namespaceMappings, configPath } = options;
let { modifyAssetLocation } = getConfig(configPath);

const adjustedCoverage = Object.keys(coverage).reduce((memo, filePath) => {
let relativeToProjectRoot = adjustCoverageKey(
root,
Expand Down
Loading