-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathv2-addon-type-module-test.ts
More file actions
98 lines (84 loc) · 2.8 KB
/
v2-addon-type-module-test.ts
File metadata and controls
98 lines (84 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { appScenarios, baseV2Addon } from './scenarios';
import type { PreparedApp } from 'scenario-tester';
import QUnit from 'qunit';
import merge from 'lodash/merge';
const { module: Qmodule, test } = QUnit;
appScenarios
.only('release')
.map('v2-addon-as-type-module', async project => {
let addon = baseV2Addon();
addon.pkg.name = 'v2-addon';
addon.pkg.type = 'module';
addon.pkg.files = ['src', 'addon-main.cjs'];
addon.pkg.exports = {
'./*': './src/*.js',
'./addon-main.cjs': './addon-main.cjs',
};
addon.pkg['ember-addon'].main = 'addon-main.cjs';
merge(addon.files, {
'addon-main.cjs': `
const { addonV1Shim } = require('@embroider/addon-shim');
module.exports = addonV1Shim(__dirname);
`,
src: {
'side-effecting.js': `window.__secret_side_effect = 'hello';`,
/**
* NOTE: importSync shouldn't be used like this in practice,
* as it's meant for compatibility and macroCondition imports before we have
* support for top-level await.
*/
'demo.js': `
import { importSync } from '@embroider/macros';
importSync('./side-effecting.js');
`,
},
});
addon.linkDependency('@embroider/addon-shim', { baseDir: __dirname });
project.addDevDependency(addon);
project.linkDevDependency('@embroider/macros', { baseDir: __dirname });
merge(project.files, {
tests: {
// the app is not set up with typescript
'the-test.js': `
import { module, test } from 'qunit';
import 'v2-addon/demo';
module('v2 addon tests', function (hooks) {
test('macro condition runs without error', async function (assert) {
assert.strictEqual(window.__secret_side_effect, 'hello');
});
});
`,
},
'ember-cli-build.js': `
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function (defaults) {
let app = new EmberApp(defaults, {
});
const { compatBuild, recommendedOptions } = require('@embroider/compat');
const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
};
`,
});
})
.forEachScenario(scenario => {
Qmodule(scenario.name, function (hooks) {
let app: PreparedApp;
hooks.before(async () => {
app = await scenario.prepare();
});
Qmodule('Consuming app', function () {
test(`pnpm test`, async function (assert) {
let result = await app.execute('pnpm test');
assert.equal(result.exitCode, 0, result.output);
});
});
});
});