Skip to content

Commit

Permalink
Make embroider testing work.
Browse files Browse the repository at this point in the history
- run floating deps + try scenarios in node 12. This is to minimize frustrating test failures due to package drift, and to allow for testing embroider in CI. While officially supporting node 10 when not using embroider
- upgrade all other viable deps
- move to simple tsc -b approach
- only run embroider-safe, as embroider-optimized is not yet compatible with our tests
  • Loading branch information
stefanpenner committed Aug 10, 2021
1 parent 60b40f6 commit 3b4a57c
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 268 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

addon-test-support/**/*.js
addon-test-support/**/*.d.ts
3 changes: 1 addition & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v2
- uses: volta-cli/action@v1
with:
node-version: 10.x
node-version: 12.x
- run: yarn install --no-lockfile
- run: yarn test

Expand All @@ -59,7 +59,6 @@ jobs:
- ember-classic
- ember-default-with-jquery
- embroider-safe
- embroider-optimized

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

# tyescript related output files
addon-test-support/**/*.js
addon-test-support/**/*.d.ts
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
#
# avoid publishing .d.ts or .ts files
# until they have become enforced "public" APIs
*.ts
*.ts
# to enable d.ts consumption remove the next line
# !*.d.ts
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

addon-test-support/**/*.js
addon-test-support/**/*.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-nocheck
/* eslint-disable */


/* globals globalThis global setImmediate */

/*
Expand Down
62 changes: 59 additions & 3 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
'use strict';

const getChannelURL = require('ember-source-channel-url');
const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');

const EMBROIDER_VERSION = '^0.43.4';
const embroider = {
safe: {
name: 'embroider-safe',
npm: {
devDependencies: {
'@embroider/core': EMBROIDER_VERSION,
'@embroider/webpack': EMBROIDER_VERSION,
'@embroider/compat': EMBROIDER_VERSION,

// Webpack is a peer dependency of `@embroider/webpack`
webpack: '^5.0.0',
},
},
env: {
EMBROIDER_TEST_SETUP_OPTIONS: 'safe',
},
},

optimized: {
name: 'embroider-optimized',
npm: {
devDependencies: {
'@embroider/core': EMBROIDER_VERSION,
'@embroider/webpack': EMBROIDER_VERSION,
'@embroider/compat': EMBROIDER_VERSION,

// Webpack is a peer dependency of `@embroider/webpack`
webpack: '^5.0.0',
},
},
env: {
EMBROIDER_TEST_SETUP_OPTIONS: 'optimized',
},
},
};

// ensure @embroider/test-setup is provided via ember-try
// This is to avoid node 10 constraints when testing node 10
// ember-try & floating dependencies tests are run under node 12
// this is a compromise to prevent having to do a major version bump of this
// library at the moment. Our goal is to do so at around ember@4.4
embroider.safe.npm.devDependencies['@embroider/test-setup'] = '^0.43.0';
embroider.optimized.npm.devDependencies['@embroider/test-setup'] = '^0.43.0';

module.exports = async function () {
return {
Expand Down Expand Up @@ -104,8 +148,20 @@ module.exports = async function () {
devDependencies: {},
},
},
embroiderSafe(),
embroiderOptimized(),
embroider.safe,
// disable embroider optimized test scenarios, as the dynamism these
// tests use is not compatible with embroider we are still exploring
// appropriate paths forward.
//
// Steps to re-enable:
//
// 1. have a strategy to make this work
// 2. uncomment the next line
// embroider.optimized,
//
// 3. add "embroider-optimized" to .github/workflows/ci-build.yml's
// ember-try-scenario list.
//
],
};
};
14 changes: 12 additions & 2 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ module.exports = function (defaults) {
type: 'test',
});

const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app);
try {
const { maybeEmbroider } = require('@embroider/test-setup'); // eslint-disable-line node/no-missing-require
return maybeEmbroider(app);
} catch (e) {
// This exists, so that we can continue to support node 10 for some of our
// test scenarios. Specifically those not scenario testing embroider. As
// @embroider/test-setup and @embroider in no longer supports node 10
if (e !== null && typeof e === 'object' && e.code === 'MODULE_NOT_FOUND') {
return app.toTree();
}
throw e;
}
};
29 changes: 6 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,16 @@ module.exports = {
name: require('./package').name,

treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { ... } from 'ember-test-helpers';

let input = debugTree(tree, 'addon-test-support:input');

let compiler = this.project._incrementalTsCompiler;
if (this.isDevelopingAddon() && compiler) {
// eslint-disable-next-line node/no-unpublished-require
let TypescriptOutput = require('ember-cli-typescript/js/lib/incremental-typescript-compiler/typescript-output-plugin');
// eslint-disable-next-line node/no-unpublished-require
let MergeTrees = require('broccoli-merge-trees');

let tsTree = debugTree(
new TypescriptOutput(compiler, {
'addon-test-support/@ember/test-helpers': '@ember/test-helpers',
}),
'addon-test-support:ts'
);

input = debugTree(
new MergeTrees([input, tsTree]),
'addon-test-support:merged'
);
if (this.isDevelopingAddon()) {
const {
BroccoliBabelPresetTypeScript,
} = require('broccoli-babel-preset-typescript'); // eslint-disable-line node/no-unpublished-require
input = new BroccoliBabelPresetTypeScript([input]);
}

let output = this.preprocessJs(input, '/', this.name, {
const output = this.preprocessJs(input, '/', this.name, {
registry: this.registry,
treeType: 'addon-test-support',
});
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"test": "tests"
},
"scripts": {
"build": "ember build",
"docs": "scripts/precompile.sh && documentation build --document-exported \"addon-test-support/@ember/test-helpers/index.js\" --config documentation.yml --markdown-toc-max-depth 3 -f md -o API.md && ember ts:clean",
"prepublishOnly": "yarn babel --extensions '.ts' --presets @babel/preset-typescript addon-test-support --out-dir addon-test-support/ --ignore '**/*.d.ts'",
"clean": "git clean -x -f",
"docs": "documentation build --document-exported \"addon-test-support/@ember/test-helpers/index.js\" --config documentation.yml --markdown-toc-max-depth 3 -f md -o API.md",
"lint": "npm-run-all lint:*",
"lint:eslint": "eslint --cache .",
"lint:types": "tsc -p tsconfig.json --noEmit",
"prepublishOnly": "scripts/precompile.sh",
"postpublish": "ember ts:clean",
"postpublish": "npm-run-all clean",
"release": "release-it",
"start": "ember serve",
"test": "ember test",
Expand All @@ -44,13 +44,15 @@
"ember-destroyable-polyfill": "^2.0.3"
},
"devDependencies": {
"@babel/cli": "^7.14.8",
"@babel/preset-typescript": "^7.15.0",
"@ember/optional-features": "^2.0.0",
"@types/ember": "^3.16.5",
"@embroider/test-setup": "^0.36.0",
"@types/ember-testing-helpers": "^0.0.4",
"@types/rsvp": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"broccoli-babel-preset-typescript": "^1.0.0",
"broccoli-merge-trees": "^4.2.0",
"documentation": "^13.2.5",
"ember-auto-import": "^1.10.1",
Expand All @@ -59,7 +61,6 @@
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-shims": "^1.2.0",
"ember-cli-test-loader": "^3.0.0",
"ember-cli-typescript": "^1.5.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-fetch": "^8.1.0",
"ember-in-element-polyfill": "^1.0.1",
Expand All @@ -85,7 +86,7 @@
"typescript": "^4.3.5"
},
"engines": {
"node": "10.* || 12.* || >= 14.*"
"node": "10.* || 12.* || 14.* || 15.* || >= 16.*"
},
"publishConfig": {
"access": "public",
Expand Down Expand Up @@ -126,7 +127,7 @@
}
},
"volta": {
"node": "10.20.1",
"node": "12.22.4",
"yarn": "1.22.4"
}
}
30 changes: 0 additions & 30 deletions scripts/move-declaration-files.js

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/precompile.sh

This file was deleted.

8 changes: 1 addition & 7 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{{page-title "Dummy"}}

{{!-- The following component displays Ember's default welcome message. --}}
<WelcomePage />
{{!-- Feel free to remove this! --}}

{{outlet}}
{{outlet}}
31 changes: 15 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2017",
"target": "es2019",
"allowJs": false,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
Expand All @@ -15,36 +15,35 @@
"noImplicitReturns": true,
"noEmitOnError": false,
"noEmit": true,
"declaration": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"module": "es6",
"module": "ES2015",
"paths": {
"dummy/tests/*": [
"tests/*"
"./tests/*"
],
"dummy/*": [
"tests/dummy/app/*",
"app/*"
"./tests/dummy/app/*",
"./app/*"
],
"@ember/test-helpers": [
"addon-test-support/@ember/test-helpers"
"./addon-test-support/@ember/test-helpers"
],
"@ember/test-helpers/*": [
"addon-test-support/@ember/test-helpers/*"
"./addon-test-support/@ember/test-helpers/*"
],
"@ember/destroyable": ["node_modules/ember-destroyable-polyfill"],
"@ember/destroyable": ["./node_modules/ember-destroyable-polyfill"],
"*": [
"types/*"
"./types/*",
"./node_modules/@types/*"
]
}
},
"exclude": [
"node_modules"
],
"include": [
"app/**/*",
"addon/**/*",
"tests/**/*",
"types/**/*",
"test-support/**/*",
"addon-test-support/**/*"
"./addon-test-support/**/*.ts"
]
}
Loading

0 comments on commit 3b4a57c

Please sign in to comment.