Skip to content

Commit

Permalink
Merge pull request #234 from Turbo87/eslint
Browse files Browse the repository at this point in the history
Use ESLint and prettier
  • Loading branch information
Turbo87 authored Jan 4, 2019
2 parents f7e172d + 9b1cad9 commit 36832d4
Show file tree
Hide file tree
Showing 53 changed files with 1,923 additions and 1,526 deletions.
20 changes: 20 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
26 changes: 22 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
/* eslint-env node */

module.exports = {
root: true,
parser: 'typescript-eslint-parser',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
sourceType: 'module',
},
extends: 'eslint:recommended',
plugins: ['prettier', 'typescript'],
extends: ['eslint:recommended', 'prettier'],
env: {
browser: true
browser: true,
},
rules: {
}
'no-console': 'off',
'prettier/prettier': 'error',
},
overrides: [
{
files: ['**/*.ts'],
rules: {
// the TypeScript compiler already takes care of this and
// leaving it enabled results in false positives for interface imports
'no-dupe-class-members': 'off',
'no-unused-vars': 'off',
'no-undef': 'off',
},
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/bower_components

# misc
/.eslintcache
/.sass-cache
/connect.lock
/coverage/*
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */

module.exports = {
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
};
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install:
- yarn install --no-lockfile

script:
- yarn lint
- yarn run build
- yarn run test:coverage --runInBand
- yarn run test:ember
Expand Down
2 changes: 1 addition & 1 deletion lib/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
env: {
node: true
node: true,
},
};
64 changes: 38 additions & 26 deletions lib/__tests__/does-not-exist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,44 @@ describe('assert.dom(...).doesNotExist()', () => {

assert.dom('h1').doesNotExist();

expect(assert.results).toEqual([{
actual: 'Element h1 exists once',
expected: 'Element h1 does not exist',
message: 'Element h1 does not exist',
result: false,
}]);
expect(assert.results).toEqual([
{
actual: 'Element h1 exists once',
expected: 'Element h1 does not exist',
message: 'Element h1 does not exist',
result: false,
},
]);
});

test('fails if element exists multiple times', () => {
document.body.innerHTML = '<div></div>'.repeat(3);

assert.dom('div').doesNotExist();

expect(assert.results).toEqual([{
actual: 'Element div exists 3 times',
expected: 'Element div does not exist',
message: 'Element div does not exist',
result: false,
}]);
expect(assert.results).toEqual([
{
actual: 'Element div exists 3 times',
expected: 'Element div does not exist',
message: 'Element div does not exist',
result: false,
},
]);
});

test('succeeds if element is missing', () => {
document.body.innerHTML = '<h1 class="baz">foo</h1>bar';

assert.dom('h2').doesNotExist();

expect(assert.results).toEqual([{
actual: 'Element h2 does not exist',
expected: 'Element h2 does not exist',
message: 'Element h2 does not exist',
result: true,
}]);
expect(assert.results).toEqual([
{
actual: 'Element h2 does not exist',
expected: 'Element h2 does not exist',
message: 'Element h2 does not exist',
result: true,
},
]);
});
});

Expand All @@ -55,21 +61,27 @@ describe('assert.dom(...).doesNotExist()', () => {

assert.dom('h2').doesNotExist('foo');

expect(assert.results).toEqual([{
actual: 'Element h2 does not exist',
expected: 'Element h2 does not exist',
message: 'foo',
result: true,
}]);
expect(assert.results).toEqual([
{
actual: 'Element h2 does not exist',
expected: 'Element h2 does not exist',
message: 'foo',
result: true,
},
]);
});

test('throws for unexpected parameter types', () => {
expect(() => assert.dom(document.body).doesNotExist()).toThrow('Unexpected Parameter: [object HTMLBodyElement]');
expect(() => assert.dom(document.body).doesNotExist()).toThrow(
'Unexpected Parameter: [object HTMLBodyElement]'
);

expect(() => assert.dom(5).doesNotExist()).toThrow('Unexpected Parameter: 5');
expect(() => assert.dom(true).doesNotExist()).toThrow('Unexpected Parameter: true');
expect(() => assert.dom(undefined).doesNotExist()).toThrow('Unexpected Parameter: undefined');
expect(() => assert.dom({}).doesNotExist()).toThrow('Unexpected Parameter: [object Object]');
expect(() => assert.dom(document).doesNotExist()).toThrow('Unexpected Parameter: [object Document]');
expect(() => assert.dom(document).doesNotExist()).toThrow(
'Unexpected Parameter: [object Document]'
);
});
});
104 changes: 62 additions & 42 deletions lib/__tests__/does-not-have-attribute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jest */

import TestAssertions from "../helpers/test-assertions";
import TestAssertions from '../helpers/test-assertions';

describe('assert.dom(...).doesNotHaveAttribute()', () => {
let assert;
Expand All @@ -15,67 +15,87 @@ describe('assert.dom(...).doesNotHaveAttribute()', () => {
assert.dom('input').doesNotHaveAttribute('disabled');
assert.dom(document.querySelector('input')).doesNotHaveAttribute('disabled');

expect(assert.results).toEqual([{
actual: 'Element input does not have attribute "disabled"',
expected: 'Element input does not have attribute "disabled"',
message: 'Element input does not have attribute "disabled"',
result: true,
}, {
actual: 'Element input[type="password"][required] does not have attribute "disabled"',
expected: 'Element input[type="password"][required] does not have attribute "disabled"',
message: 'Element input[type="password"][required] does not have attribute "disabled"',
result: true,
}]);
expect(assert.results).toEqual([
{
actual: 'Element input does not have attribute "disabled"',
expected: 'Element input does not have attribute "disabled"',
message: 'Element input does not have attribute "disabled"',
result: true,
},
{
actual: 'Element input[type="password"][required] does not have attribute "disabled"',
expected: 'Element input[type="password"][required] does not have attribute "disabled"',
message: 'Element input[type="password"][required] does not have attribute "disabled"',
result: true,
},
]);
});

test('fails for wrong content (string value)', () => {
assert.dom('input').doesNotHaveAttribute('type');
assert.dom(document.querySelector('input')).doesNotHaveAttribute('type');

expect(assert.results).toEqual([{
actual: 'Element input has attribute "type" with value "password"',
expected: 'Element input does not have attribute "type"',
message: 'Element input does not have attribute "type"',
result: false,
}, {
actual: 'Element input[type="password"][required] has attribute "type" with value "password"',
expected: 'Element input[type="password"][required] does not have attribute "type"',
message: 'Element input[type="password"][required] does not have attribute "type"',
result: false,
}]);
expect(assert.results).toEqual([
{
actual: 'Element input has attribute "type" with value "password"',
expected: 'Element input does not have attribute "type"',
message: 'Element input does not have attribute "type"',
result: false,
},
{
actual:
'Element input[type="password"][required] has attribute "type" with value "password"',
expected: 'Element input[type="password"][required] does not have attribute "type"',
message: 'Element input[type="password"][required] does not have attribute "type"',
result: false,
},
]);
});

test('fails for wrong content (string value)', () => {
assert.dom('input').doesNotHaveAttribute('required');
assert.dom(document.querySelector('input')).doesNotHaveAttribute('required');

expect(assert.results).toEqual([{
actual: 'Element input has attribute "required" with value ""',
expected: 'Element input does not have attribute "required"',
message: 'Element input does not have attribute "required"',
result: false,
}, {
actual: 'Element input[type="password"][required] has attribute "required" with value ""',
expected: 'Element input[type="password"][required] does not have attribute "required"',
message: 'Element input[type="password"][required] does not have attribute "required"',
result: false,
}]);
expect(assert.results).toEqual([
{
actual: 'Element input has attribute "required" with value ""',
expected: 'Element input does not have attribute "required"',
message: 'Element input does not have attribute "required"',
result: false,
},
{
actual: 'Element input[type="password"][required] has attribute "required" with value ""',
expected: 'Element input[type="password"][required] does not have attribute "required"',
message: 'Element input[type="password"][required] does not have attribute "required"',
result: false,
},
]);
});

test('fails for missing element', () => {
assert.dom('#missing').doesNotHaveAttribute('disabled');

expect(assert.results).toEqual([{
message: 'Element #missing should exist',
result: false,
}]);
expect(assert.results).toEqual([
{
message: 'Element #missing should exist',
result: false,
},
]);
});

test('throws for unexpected parameter types', () => {
expect(() => assert.dom(5).doesNotHaveAttribute('disabled')).toThrow('Unexpected Parameter: 5');
expect(() => assert.dom(true).doesNotHaveAttribute('disabled')).toThrow('Unexpected Parameter: true');
expect(() => assert.dom(undefined).doesNotHaveAttribute('disabled')).toThrow('Unexpected Parameter: undefined');
expect(() => assert.dom({}).doesNotHaveAttribute('disabled')).toThrow('Unexpected Parameter: [object Object]');
expect(() => assert.dom(document).doesNotHaveAttribute('disabled')).toThrow('Unexpected Parameter: [object Document]');
expect(() => assert.dom(true).doesNotHaveAttribute('disabled')).toThrow(
'Unexpected Parameter: true'
);
expect(() => assert.dom(undefined).doesNotHaveAttribute('disabled')).toThrow(
'Unexpected Parameter: undefined'
);
expect(() => assert.dom({}).doesNotHaveAttribute('disabled')).toThrow(
'Unexpected Parameter: [object Object]'
);
expect(() => assert.dom(document).doesNotHaveAttribute('disabled')).toThrow(
'Unexpected Parameter: [object Document]'
);
});
});
Loading

0 comments on commit 36832d4

Please sign in to comment.