Skip to content

Commit 559a3da

Browse files
committed
Support scenario testing
1 parent a44979e commit 559a3da

15 files changed

Lines changed: 234 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
slow-test:
8181
- defaults with npm
8282
- defaults with pnpm
83+
- try-scenarios
8384
steps:
8485
- uses: actions/checkout@v4
8586
- uses: pnpm/action-setup@v4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/node_modules/
1+
/node_modules/
2+
.log/

files/.github/workflows/ci.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
name: "Tests"
3434
runs-on: ubuntu-latest
3535
timeout-minutes: 10
36+
outputs:
37+
matrix: ${{ steps.set-matrix.outputs.matrix }}
3638

3739
steps:
3840
- uses: actions/checkout@v4<% if (pnpm) { %>
@@ -45,6 +47,11 @@ jobs:
4547
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
4648
- name: Run Tests
4749
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test
50+
# For the Try Scenarios
51+
- id: set-matrix
52+
run: |
53+
<% if (pnpm) { %> echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT<% } %>
54+
<% if (npm) { %> echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT<% } %>
4855
4956
floating:
5057
name: "Floating Dependencies"
@@ -64,31 +71,29 @@ jobs:
6471
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test
6572

6673
try-scenarios:
67-
name: ${{ matrix.try-scenario }}
74+
name: ${{ matrix.name }}
6875
runs-on: ubuntu-latest
6976
needs: "test"
7077
timeout-minutes: 10
71-
7278
strategy:
7379
fail-fast: false
74-
matrix:
75-
try-scenario:
76-
- ember-lts-4.12
77-
- ember-lts-5.4
78-
- ember-release
79-
- ember-beta
80-
- ember-canary
81-
- embroider-safe
82-
- embroider-optimized
80+
matrix: ${{fromJson(needs.test.outputs.matrix)}}
8381

8482
steps:
85-
- uses: actions/checkout@v4<% if (pnpm) { %>
86-
- uses: pnpm/action-setup@v4<% } %>
83+
- uses: actions/checkout@v4
84+
- uses: pnpm/action-setup@v4
8785
- uses: actions/setup-node@v4
8886
with:
8987
node-version: 18
9088
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
89+
- name: Apply Scenario
90+
run: |
91+
<% if (pnpm) { %> pnpm dlx @embroider/try apply ${{ matrix.name }}<% } %>
92+
<% if (npm) { %> npx @embroider/try apply ${{ matrix.name }}<% } %>
9193
- name: Install Dependencies
92-
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
94+
run: <%= pnpm ? 'pnpm install --no-lockfile' : yarn ? 'yarn install --no-lockfile' : 'npm install --no-package-lock' %>
9395
- name: Run Tests
94-
run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} --skip-cleanup
96+
run: |
97+
<% if (pnpm) { %>pnpm test<% } %>
98+
<% if (npm) { %>npm test<% } %>
99+
env: ${{ matrix.env }}

files/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
/coverage/
1010
pnpm-lock.yaml
1111
config/ember-cli-update.json
12+
*.yaml
13+
*.yml
14+
*.md
15+
*.html

files/.try.mjs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export default scenarios();
2+
3+
function scenarios() {
4+
return {
5+
scenarios: [
6+
compatEmberScenario('ember-lts-4.12', '^4.12.0'),
7+
compatEmberScenario('ember-lts-5.4', '~5.4.0'),
8+
compatEmberScenario('ember-lts-5.12', '^5.12.0'),
9+
emberScenario('~6.4.0'),
10+
emberScenario('latest'),
11+
emberScenario('beta'),
12+
emberScenario('alpha'),
13+
],
14+
};
15+
}
16+
17+
function emberScenario(tag) {
18+
return {
19+
name: `ember-${tag}`,
20+
npm: {
21+
devDependencies: {
22+
'ember-source': `npm:ember-source@${tag}`,
23+
},
24+
},
25+
};
26+
}
27+
28+
function emberCliBuildJS() {
29+
return `const EmberApp = require('ember-cli/lib/broccoli/ember-app');
30+
const { compatBuild } = require('@embroider/compat');
31+
module.exports = async function (defaults) {
32+
const { buildOnce } = await import('@embroider/vite');
33+
let app = new EmberApp(defaults);
34+
return compatBuild(app, buildOnce);
35+
};`;
36+
}
37+
38+
function compatEmberScenario(name, emberVersion) {
39+
// older LTSs would also need the compat configuration
40+
let needsCompat = ['5.4.0', '4.12.0'];
41+
let needsBabelComat = needsCompat.some((v) => emberVersion.includes(v));
42+
43+
return {
44+
name,
45+
npm: {
46+
devDependencies: {
47+
'ember-source': emberVersion,
48+
'@embroider/compat': '^4.0.3',
49+
'ember-cli': '^5.12.0',
50+
'ember-auto-import': '^2.10.0',
51+
'@ember/optional-features': '^2.2.0',
52+
},
53+
},
54+
env: {
55+
ENABLE_COMPAT_BUILD: true,
56+
},
57+
files: {
58+
'ember-cli-build.js': emberCliBuildJS(),
59+
...(needsBabelComat ? { 'babel.config.cjs': compatBabel() } : {}),
60+
'config/optional-features.json': JSON.stringify({
61+
'application-template-wrapper': false,
62+
'default-async-observers': true,
63+
'jquery-integration': false,
64+
'template-only-glimmer-components': true,
65+
'no-implicit-route-model': true,
66+
}),
67+
},
68+
};
69+
}

files/babel.config.cjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const { buildMacros } = require('@embroider/macros/babel');
22

3+
const { babelCompatSupport, templateCompatSupport } = require('@embroider/compat/babel');
4+
35
const macros = buildMacros();
46

7+
// For scenario testing
8+
const isCompat = Boolean(process.env.ENABLE_COMPAT_BUILD);
9+
510
module.exports = {
611
plugins: [<% if (typescript) { %>
712
['@babel/plugin-transform-typescript', {
@@ -12,7 +17,7 @@ module.exports = {
1217
[
1318
'babel-plugin-ember-template-compilation',
1419
{
15-
transforms: [...macros.templateMacros],
20+
transforms: [...(isCompat ? templateCompatSupport() : macros.templateMacros)],
1621
},
1722
],
1823
[
@@ -23,7 +28,7 @@ module.exports = {
2328
},
2429
},
2530
],
26-
...macros.babelMacros,
31+
...(isCompat ? babelCompatSupport() : macros.babelMacros),
2732
],
2833

2934
generatorOpts: {

files/gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
dist/
33
declarations/
44

5+
# from scenarios
6+
tmp/
7+
config/optional-features.json
8+
ember-cli-build.js
9+
510
# npm/pnpm/yarn pack output
611
*.tgz
712

files/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"lint:js:fix": "eslint . --fix",<% if (typescript) { %>
2626
"lint:types": "glint",<% } %>
2727
"start": "vite dev",
28-
"test": "vite build --mode=development && testem --file testem.cjs ci",
28+
"test": "vite build --mode=development && testem --file testem.cjs ci --port 0",
2929
"prepack": "rollup --config"
3030
},
3131
"dependencies": {
@@ -80,6 +80,9 @@
8080
"type": "addon",
8181
"main": "addon-main.cjs"
8282
},
83+
"imports": {
84+
"#src/*": "./src/*"
85+
},
8386
"exports": {<% if (typescript) { %>
8487
".": {
8588
"types": "./declarations/index.d.ts",

files/vite.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { defineConfig } from 'vite';
2-
import { extensions, ember } from '@embroider/vite';
2+
import { extensions, ember, classicEmberSupport } from '@embroider/vite';
33
import { babel } from '@rollup/plugin-babel';
44

5+
// For scenario testing
6+
const isCompat = Boolean(process.env.ENABLE_COMPAT_BUILD);
7+
58
export default defineConfig({
69
plugins: [
10+
...(isCompat ? [classicEmberSupport()] : []),
711
ember(),
812
babel({
913
babelHelpers: 'inline',

tests/fixtures/default/.github/workflows/ci.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
name: "Tests"
3333
runs-on: ubuntu-latest
3434
timeout-minutes: 10
35+
outputs:
36+
matrix: ${{ steps.set-matrix.outputs.matrix }}
3537

3638
steps:
3739
- uses: actions/checkout@v4
@@ -43,6 +45,11 @@ jobs:
4345
run: npm ci
4446
- name: Run Tests
4547
run: npm run test
48+
# For the Try Scenarios
49+
- id: set-matrix
50+
run: |
51+
52+
echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT
4653
4754
floating:
4855
name: "Floating Dependencies"
@@ -61,30 +68,25 @@ jobs:
6168
run: npm run test
6269

6370
try-scenarios:
64-
name: ${{ matrix.try-scenario }}
71+
name: ${{ matrix.name }}
6572
runs-on: ubuntu-latest
6673
needs: "test"
6774
timeout-minutes: 10
68-
6975
strategy:
7076
fail-fast: false
71-
matrix:
72-
try-scenario:
73-
- ember-lts-4.12
74-
- ember-lts-5.4
75-
- ember-release
76-
- ember-beta
77-
- ember-canary
78-
- embroider-safe
79-
- embroider-optimized
77+
matrix: ${{fromJson(needs.test.outputs.matrix)}}
8078

8179
steps:
8280
- uses: actions/checkout@v4
81+
- uses: pnpm/action-setup@v4
8382
- uses: actions/setup-node@v4
8483
with:
8584
node-version: 18
86-
cache: npm
85+
cache: pnpm
86+
- name: Apply Scenario
87+
run: pnpm dlx @embroider/try apply ${{ matrix.name }}
8788
- name: Install Dependencies
88-
run: npm ci
89+
run: pnpm install --no-lockfile
8990
- name: Run Tests
90-
run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} --skip-cleanup
91+
run: pnpm test
92+
env: ${{ matrix.env }}

0 commit comments

Comments
 (0)