|
| 1 | +const { createTempDir } = require('broccoli-test-helper'); |
1 | 2 | const { setEdition, has, _getEdition } = require('./index');
|
2 | 3 |
|
3 | 4 | const { test } = QUnit;
|
4 | 5 |
|
5 | 6 | const OriginalConsole = Object.assign({}, console);
|
| 7 | +const ROOT = process.cwd(); |
6 | 8 |
|
7 | 9 | QUnit.module('@ember/edition-utils', function(hooks) {
|
8 |
| - // only a test helper **because** we don't want folks to |
9 |
| - // use this in actual shared packages, they should instead |
10 |
| - // use `has` |
11 |
| - function getEdition() { |
12 |
| - return process.env.EMBER_EDITION; |
13 |
| - } |
14 |
| - |
15 |
| - hooks.afterEach(function() { |
| 10 | + let project; |
| 11 | + |
| 12 | + hooks.beforeEach(async function() { |
| 13 | + project = await createTempDir(); |
| 14 | + process.chdir(project.path()); |
| 15 | + }); |
| 16 | + |
| 17 | + hooks.afterEach(async function() { |
16 | 18 | delete process.env.EMBER_EDITION;
|
17 | 19 | delete process.env.EMBER_VERSION;
|
18 | 20 | Object.assign(console, OriginalConsole);
|
| 21 | + |
| 22 | + process.chdir(ROOT); |
| 23 | + await project.dispose(); |
19 | 24 | });
|
20 | 25 |
|
21 | 26 | QUnit.module('setEdition', function() {
|
22 | 27 | test('the edition name that is passed, sets the edition', function(assert) {
|
| 28 | + assert.notOk(has('octane'), 'precond'); |
| 29 | + |
23 | 30 | setEdition('octane');
|
24 | 31 |
|
25 |
| - assert.strictEqual(getEdition(), 'octane'); |
| 32 | + assert.ok(has('octane')); |
26 | 33 | });
|
27 | 34 |
|
28 | 35 | test('normalizes the edition name that is passed in (lowercasing)', function(assert) {
|
| 36 | + assert.notOk(has('octane'), 'precond'); |
| 37 | + |
29 | 38 | setEdition('OCTANE');
|
30 | 39 |
|
31 |
| - assert.strictEqual(getEdition(), 'octane'); |
| 40 | + assert.ok(has('octane')); |
32 | 41 | });
|
33 | 42 | });
|
34 | 43 |
|
35 | 44 | QUnit.module('has', function() {
|
36 |
| - test('should be considered "classic" without an edition set', function(assert) { |
37 |
| - assert.ok(has('classic')); |
38 |
| - }); |
| 45 | + function setupProject(edition) { |
| 46 | + let pkg = { |
| 47 | + name: 'dummy', |
| 48 | + version: '0.0.0', |
| 49 | + }; |
| 50 | + |
| 51 | + if (edition) { |
| 52 | + pkg.ember = { edition }; |
| 53 | + } |
39 | 54 |
|
40 |
| - test('should be considered "octane" when passing octane', function(assert) { |
41 |
| - setEdition('octane'); |
| 55 | + project.write({ |
| 56 | + 'package.json': JSON.stringify(pkg, null, 2), |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + test('should be octane if project package.json is setup with edition: octane', function(assert) { |
| 61 | + setupProject('octane'); |
42 | 62 |
|
43 | 63 | assert.ok(has('octane'));
|
44 | 64 | });
|
45 | 65 |
|
46 |
| - test('should match case insensitively', function(assert) { |
47 |
| - setEdition('octane'); |
| 66 | + test('should be octane if project package.json in custom root is setup with edition: octane', function(assert) { |
| 67 | + process.chdir(ROOT); |
48 | 68 |
|
49 |
| - assert.ok(has('OCTANE')); |
50 |
| - }); |
| 69 | + setupProject('octane'); |
51 | 70 |
|
| 71 | + assert.ok(has('octane', project.path())); |
| 72 | + }); |
52 | 73 |
|
53 |
| - test('should not "have" octane, when edition is classic', function(assert) { |
54 |
| - setEdition('classic'); |
| 74 | + test('has("classic") should be true when octane is set', function(assert) { |
| 75 | + setupProject('octane'); |
55 | 76 |
|
56 |
| - assert.notOk(has('octane')); |
| 77 | + assert.ok(has('classic')); |
57 | 78 | });
|
58 | 79 |
|
59 |
| - test('should infer edition from process.env.EMBER_VERSION with a warning', function(assert) { |
60 |
| - assert.expect(2); |
| 80 | + QUnit.module('deprecated setEdition fallback', function() { |
| 81 | + test('project package.json "wins" over setEdition', function(assert) { |
| 82 | + setupProject('classic'); |
61 | 83 |
|
62 |
| - process.env.EMBER_VERSION = 'octane'; |
63 |
| - console.log = (...args) => { |
64 |
| - assert.deepEqual(args, [ |
65 |
| - 'Please update to using @ember/edition-utils. Using process.env.EMBER_VERSION to declare your application / addon as "octane" ready is deprecated.', |
66 |
| - ]); |
67 |
| - } |
| 84 | + setEdition('octane'); |
| 85 | + |
| 86 | + assert.ok(has('classic')); |
| 87 | + }); |
| 88 | + |
| 89 | + test('should be considered "classic" without an edition set', function(assert) { |
| 90 | + assert.ok(has('classic')); |
| 91 | + }); |
| 92 | + |
| 93 | + test('should be considered "octane" when passing octane', function(assert) { |
| 94 | + setEdition('octane'); |
| 95 | + |
| 96 | + assert.ok(has('octane')); |
| 97 | + }); |
| 98 | + |
| 99 | + test('should match case insensitively', function(assert) { |
| 100 | + setEdition('octane'); |
| 101 | + |
| 102 | + assert.ok(has('OCTANE')); |
| 103 | + }); |
| 104 | + |
| 105 | + |
| 106 | + test('should not be octane, when edition is setEdition("classic") [deprecated]', function(assert) { |
| 107 | + setEdition('classic'); |
| 108 | + |
| 109 | + assert.notOk(has('octane')); |
| 110 | + }); |
| 111 | + |
| 112 | + test('should infer edition from process.env.EMBER_VERSION with a warning', function(assert) { |
| 113 | + assert.expect(2); |
| 114 | + |
| 115 | + process.env.EMBER_VERSION = 'octane'; |
| 116 | + console.log = (...args) => { |
| 117 | + assert.deepEqual(args, [ |
| 118 | + 'Please update to using @ember/edition-utils. Using process.env.EMBER_VERSION to declare your application / addon as "octane" ready is deprecated.', |
| 119 | + ]); |
| 120 | + } |
68 | 121 |
|
69 |
| - assert.ok(has('octane'), 'finds process.env.EMBER_VERSION'); |
| 122 | + assert.ok(has('octane'), 'finds process.env.EMBER_VERSION'); |
| 123 | + }); |
70 | 124 | });
|
71 | 125 | });
|
72 | 126 | });
|
0 commit comments