Skip to content

Commit a666df1

Browse files
committed
Introduce failing test cases for emberjs#423, emberjs#425
1 parent e01dcdc commit a666df1

File tree

5 files changed

+78
-7
lines changed

5 files changed

+78
-7
lines changed

node-tests/addon-test.js

+46
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,52 @@ describe('ember-cli-babel', function() {
127127
});
128128
}));
129129

130+
describe('decorators and class fields', function() {
131+
it(
132+
"can compile decorators",
133+
co.wrap(function* () {
134+
input.write({
135+
"foo.js": `import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nexport default class Foo extends Component { @tracked thisIsTracked = true; }`,
136+
});
137+
138+
this.addon.project.targets = {
139+
browsers: ["last 2 chrome versions"],
140+
};
141+
142+
subject = this.addon.transpileTree(input.path(), {});
143+
144+
output = createBuilder(subject);
145+
146+
yield output.build();
147+
expect(output.read()["foo.js"]).not.to.include(
148+
"_initializerWarningHelper(_descriptor, this)"
149+
);
150+
})
151+
);
152+
153+
it(
154+
"can compile class fields",
155+
co.wrap(function* () {
156+
input.write({
157+
"foo.js": `import Component from '@ember/component';\n\nexport default class Foo extends Component { thisIsAField = true; }`,
158+
});
159+
160+
this.addon.project.targets = {
161+
browsers: ["last 2 chrome versions"],
162+
};
163+
164+
subject = this.addon.transpileTree(input.path(), {});
165+
166+
output = createBuilder(subject);
167+
168+
yield output.build();
169+
expect(output.read()["foo.js"]).not.to.include(
170+
"Decorating class property failed"
171+
);
172+
})
173+
);
174+
});
175+
130176
describe('ember modules API polyfill', function() {
131177
it("does not transpile deprecate debug tooling import paths", co.wrap(function* () {
132178
input.write({

node-tests/get-babel-options-test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe("get-babel-options", function () {
7171
expect(
7272
_addDecoratorPlugins([], {}, {}, this.addon.parent, this.addon.project)
7373
.length
74-
).to.equal(2, "plugins added correctly");
74+
).to.equal(4, "plugins added correctly");
7575
});
7676

7777
it("should include only fields if it detects decorators plugin", function () {
@@ -91,7 +91,7 @@ describe("get-babel-options", function () {
9191
this.addon.parent,
9292
this.addon.project
9393
).length
94-
).to.equal(2, "plugins were not added");
94+
).to.equal(4, "plugins were not added");
9595
});
9696

9797
it("should include only decorators if it detects class fields plugin", function () {
@@ -123,7 +123,7 @@ describe("get-babel-options", function () {
123123
this.addon.project
124124
);
125125

126-
expect(strictPlugins[1][1].loose).to.equal(
126+
expect(strictPlugins[strictPlugins.length - 1][1].loose).to.equal(
127127
false,
128128
"loose is false if no option is provided"
129129
);
@@ -136,7 +136,7 @@ describe("get-babel-options", function () {
136136
this.addon.project
137137
);
138138

139-
expect(loosePlugins[1][1].loose).to.equal(
139+
expect(loosePlugins[loosePlugins.length - 1][1].loose).to.equal(
140140
true,
141141
"loose setting added correctly"
142142
);
@@ -157,7 +157,7 @@ describe("get-babel-options", function () {
157157
"@babel/plugin-transform-typescript",
158158
"typescript still first"
159159
);
160-
expect(plugins.length).to.equal(3, "class fields and decorators added");
160+
expect(plugins.length).to.equal(5, "class fields and decorators added");
161161
});
162162

163163
it("should include class fields and decorators before typescript if not handling typescript", function () {
@@ -172,8 +172,8 @@ describe("get-babel-options", function () {
172172
this.addon.project
173173
);
174174

175-
expect(plugins.length).to.equal(3, "class fields and decorators added");
176-
expect(plugins[2]).to.equal(
175+
expect(plugins.length).to.equal(5, "class fields and decorators added");
176+
expect(plugins[4]).to.equal(
177177
"@babel/plugin-transform-typescript",
178178
"typescript is now last"
179179
);

tests/acceptance/simple-test.js

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ module('Acceptance | ES6 features work correctly', function(hooks) {
1414
assert.equal('dog', this.element.querySelector('#animal-value').textContent, 'Has class and getters/setters and decorators as ES6 feature');
1515
assert.equal('mammal', this.element.querySelector('#animal-type').textContent, 'Has class decorators as ES6 feature');
1616
assert.equal('mammal', this.element.querySelector('#static-animal-type').textContent, 'static and fields as an ES6 class feature');
17+
assert.equal('123', this.element.querySelector('#uses-decorators').textContent, 'decorated class fields work in the app')
18+
assert.equal('private field', this.element.querySelector('#gets-private-field').textContent, 'private class fields work in the app')
19+
assert.equal('private method', this.element.querySelector('#calls-private-method').textContent, 'private methods work in the app')
1720
});
1821
});

tests/dummy/app/components/basic.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Component from "@glimmer/component";
2+
import { tracked } from "@glimmer/tracking";
3+
4+
export default class Basic extends Component {
5+
@tracked someField = 123;
6+
7+
#privateField = "private field";
8+
9+
#privateMethod() {
10+
return "private method";
11+
}
12+
13+
get getsPrivateField() {
14+
return this.#privateField;
15+
}
16+
17+
get callsPrivateMethod() {
18+
return this.#privateMethod();
19+
}
20+
}

tests/dummy/app/templates/application.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
<div id="animal-type">{{animal.type}}</div>
99
<div id="static-animal-type">{{staticAnimalType}}</div>
1010

11+
<Basic />
12+
1113
{{outlet}}

0 commit comments

Comments
 (0)