-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from scottkidder/no-pause-test
Add new `no-pause-test` rule
- Loading branch information
Showing
6 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Disallow use of `pauseTest` helper in tests (no-pause-test) | ||
|
||
When `pauseTest()` is committed and run in CI it can cause runners to hang which is undesirable. | ||
|
||
|
||
## Rule Details | ||
|
||
This rule aims to prevent `pauseTest()` from being committed and run in CI. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
import { module, test } from 'qunit'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
|
||
import { pauseTest } from '@ember/test-helpers'; | ||
|
||
module('Acceptance | foo test', function(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('it hangs', async function() { | ||
await this.pauseTest(); | ||
// or | ||
await pauseTest(); | ||
}); | ||
}); | ||
``` | ||
|
||
|
||
## When Not To Use It | ||
|
||
If you have tests that call `resumeTest()` following a `pauseTest()` | ||
|
||
```js | ||
import { module, test } from 'qunit'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
|
||
import { pauseTest, resumeTest } from '@ember/test-helpers'; | ||
|
||
module('Acceptance | foo test', function(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('it runs', async function() { | ||
const promise = pauseTest(); | ||
|
||
// Do some stuff | ||
|
||
resumeTest(); // Done | ||
}); | ||
}); | ||
``` | ||
|
||
|
||
## Further Reading | ||
|
||
* [ember-test-helpers pauseTest documentation](https://github.com/emberjs/ember-test-helpers/blob/master/API.md#pausetest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const emberUtils = require('../utils/ember'); | ||
const types = require('../utils/types'); | ||
|
||
const ERROR_MESSAGE = 'Do not use `pauseTest()`'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Disallow use of `pauseTest` helper in tests.', | ||
category: 'Testing', | ||
recommended: false, | ||
}, | ||
fixable: null, | ||
}, | ||
|
||
ERROR_MESSAGE, | ||
|
||
create(context) { | ||
if (!emberUtils.isTestFile(context.getFilename())) { | ||
return {}; | ||
} | ||
|
||
return { | ||
CallExpression(node) { | ||
const { callee } = node; | ||
|
||
if ( | ||
(types.isIdentifier(callee) && callee.name === 'pauseTest') || | ||
(types.isThisExpression(callee.object) && | ||
types.isIdentifier(callee.property) && | ||
callee.property.name === 'pauseTest') | ||
) { | ||
context.report({ | ||
node, | ||
message: ERROR_MESSAGE, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use strict'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/no-pause-test'); | ||
const RuleTester = require('eslint').RuleTester; | ||
|
||
const { ERROR_MESSAGE } = rule; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
const TEST_FILE_NAME = 'some-test.js'; | ||
|
||
let ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
}); | ||
|
||
ruleTester.run('no-pause-test', rule, { | ||
valid: [ | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: "run(() => { console.log('Hello World.'); });", | ||
}, | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: 'myCustomClass.pauseTest(myFunction);', | ||
}, | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: 'pauseTest.otherFunction(myFunction);', | ||
}, | ||
{ | ||
filename: 'not-a-test-file.js', | ||
code: 'async () => { await this.pauseTest(); }', | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: 'async () => { await this.pauseTest(); }', | ||
output: null, | ||
errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }], | ||
}, | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: 'async () => { await pauseTest(); }', | ||
output: null, | ||
errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }], | ||
}, | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: ` | ||
test('foo', async function(assert) { | ||
await this.pauseTest(); | ||
}); | ||
`, | ||
output: null, | ||
errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }], | ||
}, | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: ` | ||
test('bar', async function(assert) { | ||
await pauseTest(); | ||
}); | ||
`, | ||
output: null, | ||
errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }], | ||
}, | ||
{ | ||
filename: TEST_FILE_NAME, | ||
code: ` | ||
test('baz', function(assert) { | ||
this.pauseTest(); | ||
}); | ||
`, | ||
output: null, | ||
errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }], | ||
}, | ||
], | ||
}); |