-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
126 lines (90 loc) · 3.28 KB
/
test.js
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const { createTempDir } = require('broccoli-test-helper');
const { setEdition, has, _getEdition } = require('./index');
const { test } = QUnit;
const OriginalConsole = Object.assign({}, console);
const ROOT = process.cwd();
QUnit.module('@ember/edition-utils', function(hooks) {
let project;
hooks.beforeEach(async function() {
project = await createTempDir();
process.chdir(project.path());
});
hooks.afterEach(async function() {
delete process.env.EMBER_EDITION;
delete process.env.EMBER_VERSION;
Object.assign(console, OriginalConsole);
process.chdir(ROOT);
await project.dispose();
});
QUnit.module('setEdition', function() {
test('the edition name that is passed, sets the edition', function(assert) {
assert.notOk(has('octane'), 'precond');
setEdition('octane');
assert.ok(has('octane'));
});
test('normalizes the edition name that is passed in (lowercasing)', function(assert) {
assert.notOk(has('octane'), 'precond');
setEdition('OCTANE');
assert.ok(has('octane'));
});
});
QUnit.module('has', function() {
function setupProject(edition) {
let pkg = {
name: 'dummy',
version: '0.0.0',
};
if (edition) {
pkg.ember = { edition };
}
project.write({
'package.json': JSON.stringify(pkg, null, 2),
});
}
test('should be octane if project package.json is setup with edition: octane', function(assert) {
setupProject('octane');
assert.ok(has('octane'));
});
test('should be octane if project package.json in custom root is setup with edition: octane', function(assert) {
process.chdir(ROOT);
setupProject('octane');
assert.ok(has('octane', project.path()));
});
test('has("classic") should be true when octane is set', function(assert) {
setupProject('octane');
assert.ok(has('classic'));
});
QUnit.module('deprecated setEdition fallback', function() {
test('project package.json "wins" over setEdition', function(assert) {
setupProject('classic');
setEdition('octane');
assert.ok(has('classic'));
});
test('should be considered "classic" without an edition set', function(assert) {
assert.ok(has('classic'));
});
test('should be considered "octane" when passing octane', function(assert) {
setEdition('octane');
assert.ok(has('octane'));
});
test('should match case insensitively', function(assert) {
setEdition('octane');
assert.ok(has('OCTANE'));
});
test('should not be octane, when edition is setEdition("classic") [deprecated]', function(assert) {
setEdition('classic');
assert.notOk(has('octane'));
});
test('should infer edition from process.env.EMBER_VERSION with a warning', function(assert) {
assert.expect(2);
process.env.EMBER_VERSION = 'octane';
console.log = (...args) => {
assert.deepEqual(args, [
'Please update to using @ember/edition-utils. Using process.env.EMBER_VERSION to declare your application / addon as "octane" ready is deprecated.',
]);
}
assert.ok(has('octane'), 'finds process.env.EMBER_VERSION');
});
});
});
});