-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathno-qunit-start-in-tests.js
More file actions
89 lines (79 loc) · 2.92 KB
/
no-qunit-start-in-tests.js
File metadata and controls
89 lines (79 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @fileoverview forbid QUnit.start() within tests or test hooks
* @author Kevin Partington
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-qunit-start-in-tests"),
RuleTester = require("eslint").RuleTester;
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* @param {string} context
* @returns {{messageId: string, data: Record<string, string>}}
*/
function createError(context) {
return {
messageId: "noQUnitStartInTests",
data: {
context,
},
};
}
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("no-qunit-start-in-tests", rule, {
valid: [
// Must allow QUnit.start() outside of test contexts
"QUnit.start();",
// Must allow QUnit.start() in module properties that are not hooks
'QUnit.module("a module", { notAHook: function() { QUnit.start(); } });',
],
invalid: [
{
code: 'QUnit.asyncTest("test", function(assert) { QUnit.start(); });',
errors: [createError("test")],
},
// Module hooks
{
code: 'QUnit.module("module", { beforeEach: function() { QUnit.start(); } });',
errors: [createError("beforeEach hook")],
},
{
code: 'QUnit.module("module", { afterEach: function() { QUnit.start(); } });',
errors: [createError("afterEach hook")],
},
{
code: 'QUnit.module("module", { before: function() { QUnit.start(); } });',
errors: [createError("before hook")],
},
{
code: 'QUnit.module("module", { after: function() { QUnit.start(); } });',
errors: [createError("after hook")],
},
{
code: 'QUnit.module("module", { setup: function() { QUnit.start(); } });',
errors: [createError("setup hook")],
},
{
code: 'QUnit.module("module", { teardown: function() { QUnit.start(); } });',
errors: [createError("teardown hook")],
},
// Module hooks (new-style modules)
/* Enable when supported
{
code: "QUnit.module(\"module\", function(hooks) { hooks.beforeEach(function() { QUnit.start(); }); });",
errors: [createError("beforeEach hook")]
},
{
code: "QUnit.module(\"module\", function(hooks) { hooks.afterEach(function() { QUnit.start(); }); });",
errors: [createError("afterEach hook")]
}
*/
],
});