Skip to content
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

Embroider support when staticAddonTestSupportTrees enabled #599

Merged
merged 3 commits into from
Sep 30, 2020
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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ jobs:
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-classic
- env: EMBER_TRY_SCENARIO=embroider
- env: EMBER_TRY_SCENARIO=embroider TEST_FRAMEWORK=ember-mocha
- env: EMBER_TRY_SCENARIO=embroider-optimized
- env: EMBER_TRY_SCENARIO=embroider-optimized TEST_FRAMEWORK=ember-mocha

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Expand Down
10 changes: 5 additions & 5 deletions addon-test-support/-private/get-test-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals require, requirejs */
import { dependencySatisfies, macroCondition, importSync } from '@embroider/macros';

/**
* Returns ember-exam-qunit-test-loader or ember-exam-mocha-test-loader
Expand All @@ -8,11 +8,11 @@
* @return {Object}
*/
export default function getTestLoader() {
if (requirejs.entries['ember-qunit/test-loader']) {
const EmberExamQUnitTestLoader = require('./ember-exam-qunit-test-loader');
if (macroCondition(dependencySatisfies('ember-qunit', '*'))){
const EmberExamQUnitTestLoader = importSync('./ember-exam-qunit-test-loader');
return EmberExamQUnitTestLoader['default'];
} else if (requirejs.entries['ember-mocha/test-loader']) {
const EmberExamMochaTestLoader = require('./ember-exam-mocha-test-loader');
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))){
const EmberExamMochaTestLoader = importSync('./ember-exam-mocha-test-loader');
return EmberExamMochaTestLoader['default'];
}

Expand Down
11 changes: 7 additions & 4 deletions addon-test-support/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* globals require */

import loadEmberExam from 'ember-exam/test-support/load';
import { dependencySatisfies, macroCondition, importSync } from '@embroider/macros';

/**
* Equivalent to ember-qunit or ember-mocha's loadTest() except this does not create a new TestLoader instance
Expand All @@ -26,14 +25,18 @@ function loadTests(testLoader) {
* @param {*} qunitOptions
*/
export default function start(qunitOptions) {
const framework = require.has('ember-qunit') ? 'qunit' : 'mocha';
const modifiedOptions = qunitOptions || Object.create(null);
modifiedOptions.loadTests = false;

const testLoader = loadEmberExam();
loadTests(testLoader);

const emberTestFramework = require(`ember-${framework}`);
let emberTestFramework;
if (macroCondition(dependencySatisfies('ember-qunit', '*'))){
emberTestFramework = importSync('ember-qunit');
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
emberTestFramework = importSync('ember-mocha');
}

if (emberTestFramework.start) {
emberTestFramework.start(modifiedOptions);
Expand Down
20 changes: 20 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ module.exports = async function() {
edition: 'classic'
}
}
},
{
name: 'embroider',
npm: {
devDependencies: {
'@embroider/core': '*',
'@embroider/webpack': '*',
'@embroider/compat': '*',
},
},
},
{
name: 'embroider-optimized',
npm: {
devDependencies: {
'@embroider/core': '*',
'@embroider/webpack': '*',
'@embroider/compat': '*',
},
}
}
]
};
Expand Down
20 changes: 19 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,23 @@ module.exports = function(defaults) {
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
// Use embroider if it's present (it can get added by ember-try)
if ('@embroider/core' in app.dependencies()) {
/* eslint-disable node/no-missing-require, node/no-extraneous-require */
const { Webpack } = require('@embroider/webpack');
const { compatBuild } = require('@embroider/compat');
/* eslint-enable node/no-missing-require, node/no-extraneous-require */
let config = {};
if (process.env.EMBER_TRY_SCENARIO === 'embroider-optimized') {
config = {
staticAddonTrees: true,
staticAddonTestSupportTrees: true,
staticHelpers: true,
staticComponents: true,
}
}
return compatBuild(app, Webpack, config);
} else {
return app.toTree();
}
};
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"test:node": "nyc mocha 'node-tests/**/*-test.js'"
},
"dependencies": {
"@embroider/macros": "^0.26.0",
"chalk": "^4.1.0",
"cli-table3": "^0.6.0",
"debug": "^4.1.0",
Expand All @@ -46,7 +47,7 @@
"babel-eslint": "^10.1.0",
"codeclimate-test-reporter": "^0.5.0",
"ember-cli": "^3.21.2",
"ember-cli-addon-docs": "^0.6.15",
"ember-cli-addon-docs": "^0.10.0",
"ember-cli-addon-docs-yuidoc": "^0.2.4",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-deploy": "^1.0.2",
Expand Down Expand Up @@ -80,6 +81,18 @@
"sinon": "^9.0.3",
"testdouble": "^3.16.1"
},
"peerDependencies": {
"ember-mocha": "*",
"ember-qunit": "*"
},
"peerDependenciesMeta": {
"ember-qunit": {
"optional": true
},
"ember-mocha": {
"optional": true
}
},
"engines": {
"node": "10.* || >= 12"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import { setResolver } from '@ember/test-helpers';
import resolver from './helpers/resolver';
import start from 'ember-exam/test-support/start';
import { macroCondition, dependencySatisfies } from '@embroider/macros';

const oppositeFramework = !require.has('ember-qunit') ? 'qunit' : 'mocha';
const oppositeFramework = macroCondition(dependencySatisfies('ember-qunit', '*')) ? 'mocha': 'qunit';

Object.keys(require.entries).forEach((entry) => {
if (entry.indexOf(oppositeFramework) !== -1) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mocha/testem-output-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import TestemOutput from 'ember-exam/test-support/-private/patch-testem-output';
import * as TestemOutput from 'ember-exam/test-support/-private/patch-testem-output';

describe('Unit | Mocha | patch-testem-output', () => {
it('add partition number to test name when `split` is passed', function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/qunit/testem-output-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import TestemOutput from 'ember-exam/test-support/-private/patch-testem-output';
import * as TestemOutput from 'ember-exam/test-support/-private/patch-testem-output';

module('Unit | Qunit | patch-testem-output', () => {
test('add partition number to test name when `split` is passed', function(assert) {
Expand Down
Loading