Skip to content

Commit

Permalink
support ember test --environment=production
Browse files Browse the repository at this point in the history
  • Loading branch information
steveszc committed Mar 11, 2021
1 parent e4a78c6 commit 6bbc305
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,47 @@ Whenever you run your tests in Chrome via Testem (via `ember test` or `ember tes

When run in CI (via `ember test`/`ember exam`), this addon will ensure that your tests fail if a memory leak is introduced by a commit or PR.

#### A note about production and ci environments
It may be desirable to run memory leak detection on a production build of the app using `ember test --environment=production`.
Production builds normally mangle class names, which breaks our ability to detect memory leaks, so this needs to be disabled.

```js
//ember-cli-build.js

'ember-cli-terser': {
terser: {
compress: { keep_classnames: true },
mangle: { keep_classnames: true }
}
}
```

Production and CI environments also (by default) add IE11 as a compile target, which will result in classes being transpiled away, so we need to remove this as well.
```js
//config/targets.js

'use strict';

const browsers = [
'last 1 Chrome versions',
'last 1 Firefox versions',
'last 1 Safari versions'
];

// const isCI = Boolean(process.env.CI);
// const isProduction = process.env.EMBER_ENV === 'production';

// if (isCI || isProduction) {
// browsers.push('ie 11');
// }

module.exports = {
browsers
};
```

Both of these changes can be optionally implemented using ENV variables to ensure we are only making these changes when we want to run memory leak detection.

### Dev

When run during development, (via `ember test --server`) memory leaks can be detected after running individual tests or modules via the QUnit UI's filter input or module select. This enables a TDD-like experience for fixing memory leaks.
Expand Down
7 changes: 6 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
// Add options here
'ember-cli-terser': {
terser: {
compress: { keep_classnames: true },
mangle: { keep_classnames: true }
}
}
});

/*
Expand Down
13 changes: 13 additions & 0 deletions node-tests/acceptance/memory-leak-detector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ describe("Acceptance | Memory leak detection", function () {
}
});

it("fails tests when memory leak is detected in production mode", async function () {
try {
await execa("ember", ["test", "--environment=production"]);
} catch ({ exitCode, stdout }) {
assert.strictEqual(exitCode, 1, "Exits with non-zero status code");
assert(stdout.includes("LeakyService"), "Reports the leaked service");
assert(
!stdout.includes("NonleakyService"),
"Only reports the leaked service"
);
}
});

it("passes tests if no memory leaks are detected", async function () {
let { exitCode } = await execa("ember", ["test", "--filter=nonleaky"]);
assert.strictEqual(exitCode, 0, "Exits with a zero status code");
Expand Down
4 changes: 0 additions & 4 deletions tests/dummy/config/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ const browsers = [
const isCI = Boolean(process.env.CI);
const isProduction = process.env.EMBER_ENV === 'production';

if (isCI || isProduction) {
browsers.push('ie 11');
}

module.exports = {
browsers
};

0 comments on commit 6bbc305

Please sign in to comment.