Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some tests by setting parserOptions globally instead of in each individual test case #570

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 26 additions & 105 deletions tests/lib/rules/alias-model-in-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,122 +9,51 @@ const RuleTester = require('eslint').RuleTester;
// Tests
// ------------------------------------------------------------------------------

const eslintTester = new RuleTester();
const eslintTester = new RuleTester({
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
});

eslintTester.run('alias-model-in-controller', rule, {
valid: [
// direct alias

{
code: 'export default Ember.Controller.extend({nail: alias("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: computed.alias("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: Ember.computed.alias("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: readOnly("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: computed.readOnly("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: Ember.computed.readOnly("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: reads("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: computed.reads("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: Ember.computed.reads("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code:
'export default Ember.Controller.extend(TestMixin, {nail: Ember.computed.alias("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code:
'export default Ember.Controller.extend(TestMixin, TestMixin2, {nail: Ember.computed.alias("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
'export default Ember.Controller.extend({nail: alias("model")});',
'export default Ember.Controller.extend({nail: computed.alias("model")});',
'export default Ember.Controller.extend({nail: Ember.computed.alias("model")});',
'export default Ember.Controller.extend({nail: readOnly("model")});',
'export default Ember.Controller.extend({nail: computed.readOnly("model")});',
'export default Ember.Controller.extend({nail: Ember.computed.readOnly("model")});',
'export default Ember.Controller.extend({nail: reads("model")});',
'export default Ember.Controller.extend({nail: computed.reads("model")});',
'export default Ember.Controller.extend({nail: Ember.computed.reads("model")});',
'export default Ember.Controller.extend(TestMixin, {nail: Ember.computed.alias("model")});',
'export default Ember.Controller.extend(TestMixin, TestMixin2, {nail: Ember.computed.alias("model")});',
{
filename: 'example-app/controllers/path/to/some-feature.js',
code: 'export default CustomController.extend({nail: alias("model")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},

// nested alias

{
code: 'export default Ember.Controller.extend({nail: alias("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: computed.alias("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: Ember.computed.alias("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: readOnly("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: computed.readOnly("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code:
'export default Ember.Controller.extend({nail: Ember.computed.readOnly("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: reads("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: computed.reads("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Ember.Controller.extend({nail: Ember.computed.reads("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code:
'export default Ember.Controller.extend(TestMixin, {nail: Ember.computed.alias("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code:
'export default Ember.Controller.extend(TestMixin, TestMixin2, {nail: Ember.computed.alias("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
'export default Ember.Controller.extend({nail: alias("model.nail")});',
'export default Ember.Controller.extend({nail: computed.alias("model.nail")});',
'export default Ember.Controller.extend({nail: Ember.computed.alias("model.nail")});',
'export default Ember.Controller.extend({nail: readOnly("model.nail")});',
'export default Ember.Controller.extend({nail: computed.readOnly("model.nail")});',
'export default Ember.Controller.extend({nail: Ember.computed.readOnly("model.nail")});',
'export default Ember.Controller.extend({nail: reads("model.nail")});',
'export default Ember.Controller.extend({nail: computed.reads("model.nail")});',
'export default Ember.Controller.extend({nail: Ember.computed.reads("model.nail")});',
'export default Ember.Controller.extend(TestMixin, {nail: Ember.computed.alias("model.nail")});',
'export default Ember.Controller.extend(TestMixin, TestMixin2, {nail: Ember.computed.alias("model.nail")});',
{
filename: 'example-app/controllers/path/to/some-feature.js',
code: 'export default CustomController.extend({nail: alias("model.nail")});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
],
invalid: [
{
code: 'export default Ember.Controller.extend({});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -134,7 +63,6 @@ eslintTester.run('alias-model-in-controller', rule, {
},
{
code: 'export default Ember.Controller.extend({resetPassword: service()});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -144,7 +72,6 @@ eslintTester.run('alias-model-in-controller', rule, {
},
{
code: 'export default Ember.Controller.extend({resetPassword: inject.service()});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -154,7 +81,6 @@ eslintTester.run('alias-model-in-controller', rule, {
},
{
code: 'export default Ember.Controller.extend({resetPassword: Ember.inject.service()});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -164,7 +90,6 @@ eslintTester.run('alias-model-in-controller', rule, {
},
{
code: 'export default Ember.Controller.extend(TestMixin, {});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -174,7 +99,6 @@ eslintTester.run('alias-model-in-controller', rule, {
},
{
code: 'export default Ember.Controller.extend(TestMixin, TestMixin2, {});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -185,7 +109,6 @@ eslintTester.run('alias-model-in-controller', rule, {
{
filename: 'example-app/controllers/path/to/some-feature.js',
code: 'export default CustomController.extend({});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -196,7 +119,6 @@ eslintTester.run('alias-model-in-controller', rule, {
{
filename: 'example-app/some-feature/controller.js',
code: 'export default CustomController.extend({});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand All @@ -207,7 +129,6 @@ eslintTester.run('alias-model-in-controller', rule, {
{
filename: 'example-app/twisted-path/some-file.js',
code: 'export default Controller.extend({});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand Down
16 changes: 6 additions & 10 deletions tests/lib/rules/closure-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ const { ERROR_MESSAGE } = rule;
// Tests
// ------------------------------------------------------------------------------

const eslintTester = new RuleTester();
const eslintTester = new RuleTester({
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
});

eslintTester.run('closure-actions', rule, {
valid: [
{
code: 'export default Component.extend();',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
{
code: 'export default Component.extend({actions: {pushLever() {this.attr.boom();}}});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
'export default Component.extend();',
'export default Component.extend({actions: {pushLever() {this.attr.boom();}}});',
],
invalid: [
{
code:
'export default Component.extend({actions: {pushLever() {this.sendAction("detonate");}}});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand Down
12 changes: 5 additions & 7 deletions tests/lib/rules/jquery-ember-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ const RuleTester = require('eslint').RuleTester;
// Tests
// ------------------------------------------------------------------------------

const eslintTester = new RuleTester();
const eslintTester = new RuleTester({
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
});

eslintTester.run('jquery-ember-run', rule, {
valid: [
{
code:
'Ember.$("#something-rendered-by-jquery-plugin").on("click", () => {Ember.run.bind(this, this._handlerActionFromController);});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
},
'Ember.$("#something-rendered-by-jquery-plugin").on("click", () => {Ember.run.bind(this, this._handlerActionFromController);});',
],
invalid: [
{
code:
'Ember.$("#something-rendered-by-jquery-plugin").on("click", () => {this._handlerActionFromController();});',
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
output: null,
errors: [
{
Expand Down
Loading