Skip to content

Commit

Permalink
add decorator and class field acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Mar 16, 2019
1 parent 4e19548 commit 766f277
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 35 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"semver": "^5.5.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"broccoli-test-helper": "^1.4.0",
"chai": "^4.1.2",
"co": "^4.6.0",
Expand Down
4 changes: 3 additions & 1 deletion tests/acceptance/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module('Acceptance | ES6 features work correctly', function(hooks) {
assert.equal('Test Value', this.element.querySelector('#test-input').value, 'Has arrow functions and template string as ES6 feature');
assert.equal('one', this.element.querySelector('#first-value').textContent, 'Has generators as ES6 feature');
assert.equal('two', this.element.querySelector('#last-value').textContent, 'Has generators as ES6 feature');
assert.equal('dog', this.element.querySelector('#animal-value').textContent, 'Has class and getters/setters as ES6 feature');
assert.equal('dog', this.element.querySelector('#animal-value').textContent, 'Has class and getters/setters and decorators as ES6 feature');
assert.equal('mammal', this.element.querySelector('#animal-type').textContent, 'Has class decorators as ES6 feature');
assert.equal('mammal', this.element.querySelector('#static-animal-type').textContent, 'static and fields as an ES6 class feature');
});
});
28 changes: 22 additions & 6 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import Controller from '@ember/controller';
import { computed } from "@ember/object";
import { A } from "@ember/array";
import { computed } from '@ember/object';
import { A } from '@ember/array';
import Animal from 'dummy/utils/class-animal';

export default Controller.extend({
init() {
this._super(...arguments);
this.animal = new Animal('dog');
},

animalName: computed({
get() {
const animal = new Animal('dog');
return animal.name;
}
return this.animal.name;
},
}),

staticAnimalType: computed({
get() {
return Animal.type;
},
}),

// Just a very roundabout way of using some ES6 features
value: ((test = 'Test') => `${test} ${'Value'}`)(),

// Test a generator (needs the regenerator runtime) and some ES6 constructs (requires the corejs polyfill)
values: A(Array.from({ *[Symbol.iterator]() { yield 'one'; yield 'two'; } }))
values: A(
Array.from({
*[Symbol.iterator]() {
yield 'one';
yield 'two';
},
})
),
});
5 changes: 3 additions & 2 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<div id="first-value">{{values.firstObject}}</div>
<div id="last-value">{{values.lastObject}}</div>
<div id="animal-value">{{animalName}}</div>
<div id="animal-type">{{animal.type}}</div>
<div id="static-animal-type">{{staticAnimalType}}</div>


{{outlet}}
{{outlet}}
24 changes: 18 additions & 6 deletions tests/dummy/app/utils/class-animal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
function nameMacro(prototye, key, desc) {
desc.get = function() {
return this._name;
};

return desc;
}

function addType(target) {
target.prototype.type = target.type;
}

@addType
class Animal {
constructor(name) {
this._name = name
}
static type = 'mammal';

get name() {
return this._name
constructor(name) {
this._name = name;
}

@nameMacro
set name(name) {
this._name = name
this._name = name;
}
}

Expand Down
60 changes: 40 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,16 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@babel/parser@^7.0.0", "@babel/parser@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.3.4.tgz#a43357e4bbf4b92a437fb9e465c192848287f27c"
integrity sha512-tXZCqWtlOOP4wgCp6RjRvLmfuhnqTLy9VHwRochJBCP2nDm27JnnuFEnXFASVyQNHk36jD1tAammsCEEqgscIQ==

"@babel/parser@^7.1.2", "@babel/parser@^7.1.6", "@babel/parser@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.2.0.tgz#02d01dbc330b6cbf36b76ac93c50752c69027065"
integrity sha512-M74+GvK4hn1eejD9lZ7967qAwvqTZayQa3g10ag4s9uewgR7TKjeaT0YMyoq+gVfKYABiWZ4MQD701/t5e1Jhg==

"@babel/parser@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.3.4.tgz#a43357e4bbf4b92a437fb9e465c192848287f27c"
integrity sha512-tXZCqWtlOOP4wgCp6RjRvLmfuhnqTLy9VHwRochJBCP2nDm27JnnuFEnXFASVyQNHk36jD1tAammsCEEqgscIQ==

"@babel/plugin-proposal-async-generator-functions@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e"
Expand Down Expand Up @@ -646,6 +646,21 @@
"@babel/parser" "^7.1.2"
"@babel/types" "^7.1.2"

"@babel/traverse@^7.0.0", "@babel/traverse@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.3.4.tgz#1330aab72234f8dea091b08c4f8b9d05c7119e06"
integrity sha512-TvTHKp6471OYEcE/91uWmhR6PrrYywQntCHSaZ8CM8Vmp+pjAusal4nGB2WCCQd0rvI7nOMKn9GnbcvTUz3/ZQ==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.3.4"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.0.0"
"@babel/parser" "^7.3.4"
"@babel/types" "^7.3.4"
debug "^4.1.0"
globals "^11.1.0"
lodash "^4.17.11"

"@babel/traverse@^7.1.0", "@babel/traverse@^7.1.5", "@babel/traverse@^7.1.6":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.1.6.tgz#c8db9963ab4ce5b894222435482bd8ea854b7b5c"
Expand All @@ -661,21 +676,6 @@
globals "^11.1.0"
lodash "^4.17.10"

"@babel/traverse@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.3.4.tgz#1330aab72234f8dea091b08c4f8b9d05c7119e06"
integrity sha512-TvTHKp6471OYEcE/91uWmhR6PrrYywQntCHSaZ8CM8Vmp+pjAusal4nGB2WCCQd0rvI7nOMKn9GnbcvTUz3/ZQ==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.3.4"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.0.0"
"@babel/parser" "^7.3.4"
"@babel/types" "^7.3.4"
debug "^4.1.0"
globals "^11.1.0"
lodash "^4.17.11"

"@babel/types@^7.0.0", "@babel/types@^7.1.2", "@babel/types@^7.1.6", "@babel/types@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.2.0.tgz#7941c5b2d8060e06f9601d6be7c223eef906d5d8"
Expand Down Expand Up @@ -1061,6 +1061,18 @@ babel-core@^6.26.0:
slash "^1.0.0"
source-map "^0.5.7"

babel-eslint@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.1.tgz#919681dc099614cd7d31d45c8908695092a1faed"
integrity sha512-z7OT1iNV+TjOwHNLLyJk+HN+YVWX+CLE6fPD2SymJZOZQBs+QIexFjhm4keGTm8MW9xr4EC9Q0PbaLB24V5GoQ==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.0.0"
"@babel/traverse" "^7.0.0"
"@babel/types" "^7.0.0"
eslint-scope "3.7.1"
eslint-visitor-keys "^1.0.0"

babel-generator@^6.26.0:
version "6.26.1"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.1.tgz#1844408d3b8f0d35a404ea7ac180f087a601bd90"
Expand Down Expand Up @@ -3429,6 +3441,14 @@ eslint-plugin-node@^7.0.1:
resolve "^1.8.1"
semver "^5.5.0"

eslint-scope@3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
integrity sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-scope@^3.7.1:
version "3.7.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.3.tgz#bb507200d3d17f60247636160b4826284b108535"
Expand Down

0 comments on commit 766f277

Please sign in to comment.