Skip to content

Commit

Permalink
Add test for useEmberModule
Browse files Browse the repository at this point in the history
  • Loading branch information
patocallaghan committed Mar 10, 2021
1 parent 38517d1 commit 07ea140
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/babel-options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,19 @@ function _getEmberModulesAPIPolyfill(config, parent, project) {

if (_emberVersionRequiresModulesAPIPolyfill()) {
const ignore = _getEmberModulesAPIIgnore(parent, project);
const useEmberModule = _shouldDeprecateGlobalEmber(parent);

return [
[require.resolve("babel-plugin-ember-modules-api-polyfill"), { ignore }],
[require.resolve("babel-plugin-ember-modules-api-polyfill"), { ignore, useEmberModule }],
];
}
}

function _shouldDeprecateGlobalEmber(parent) {
let checker = new VersionChecker(parent).for('ember-source', "npm");
return checker.exists() && checker.gte("3.27.0-alpha.1")
}

function _getEmberModulesAPIIgnore(parent, project) {
const ignore = {
"@ember/debug": ["assert", "deprecate", "warn"],
Expand Down
92 changes: 92 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,98 @@ describe('ember-cli-babel', function() {
expect(contents).to.include('inspect.call');
expect(contents).to.not.include('assert');
}));

describe('useEmberModule', function() {
let dependencies;

beforeEach(function() {
dependencies = {};
let project = {
root: input.path(),
emberCLIVersion: () => '2.16.2',
dependencies() { return dependencies; },
addons: [],
targets: {
browsers: ['ie 11'],
},
};

this.addon = new Addon({
project,
parent: project,
ui: this.ui,
});

project.addons.push(this.addon);
});

function buildEmberSourceFixture( version ) {
return {
node_modules: {
'ember-source': {
'package.json': JSON.stringify({ name: 'ember-source', version }),
'index.js': 'module.exports = {};',
},
}
};
}

it("should not replace imports using useEmberModule", co.wrap(function* () {
const PRE_GLOBAL_RESOLVER_DEPRECATION_VERSION = '3.26.0';
dependencies['ember-source'] = PRE_GLOBAL_RESOLVER_DEPRECATION_VERSION;
input.write(buildEmberSourceFixture(PRE_GLOBAL_RESOLVER_DEPRECATION_VERSION));
input.write({
"foo.js": `import Component from '@ember/component'; Component.extend()`,
"app.js": `import Application from '@ember/application'; Application.extend()`
});

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", [], function () {\n "use strict";\n\n Ember.Component.extend();\n});`,
"app.js": `define("app", [], function () {\n "use strict";\n\n Ember.Application.extend();\n});`,
"node_modules": {
"ember-source": {
"index.js": "define(\"node_modules/ember-source/index\", [], function () {\n \"use strict\";\n\n module.exports = {};\n});",
"package.json": "{\"name\":\"ember-source\",\"version\":\"3.26.0\"}"
}
}
});
}));

it("should replace imports using useEmberModule", co.wrap(function* () {
const POST_GLOBAL_RESOLVER_DEPRECATION_VERSION = '3.27.0';
dependencies['ember-source'] = POST_GLOBAL_RESOLVER_DEPRECATION_VERSION;
input.write(buildEmberSourceFixture(POST_GLOBAL_RESOLVER_DEPRECATION_VERSION));
input.write({
"foo.js": `import Component from '@ember/component'; Component.extend()`,
"app.js": `import Application from '@ember/application'; Application.extend()`
});

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", ["ember"], function (_ember2) {\n "use strict";\n\n _ember2.default.Component.extend();\n});`,
"app.js": `define("app", ["ember"], function (_ember2) {\n "use strict";\n\n _ember2.default.Application.extend();\n});`,
"node_modules": {
"ember-source": {
"index.js": "define(\"node_modules/ember-source/index\", [], function () {\n \"use strict\";\n\n module.exports = {};\n});",
"package.json": "{\"name\":\"ember-source\",\"version\":\"3.27.0\"}"
}
}
});
}));
});
});

describe('debug macros', function() {
Expand Down

0 comments on commit 07ea140

Please sign in to comment.