/
require-await.js
88 lines (79 loc) · 2.92 KB
/
require-await.js
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
/**
* @fileoverview Tests for require-await rule.
* @author Toru Nagashima
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/require-await"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 2018
}
});
ruleTester.run("require-await", rule, {
valid: [
"async function foo() { await doSomething() }",
"(async function() { await doSomething() })",
"async () => { await doSomething() }",
"async () => await doSomething()",
"({ async foo() { await doSomething() } })",
"class A { async foo() { await doSomething() } }",
"(class { async foo() { await doSomething() } })",
"async function foo() { await async () => { await doSomething() } }",
// empty functions are ok.
"async function foo() {}",
"async () => {}",
// normal functions are ok.
"function foo() { doSomething() }",
// for-await-of
"async function foo() { for await (x of xs); }"
],
invalid: [
{
code: "async function foo() { doSomething() }",
errors: ["Async function 'foo' has no 'await' expression."]
},
{
code: "(async function() { doSomething() })",
errors: ["Async function has no 'await' expression."]
},
{
code: "async () => { doSomething() }",
errors: ["Async arrow function has no 'await' expression."]
},
{
code: "async () => doSomething()",
errors: ["Async arrow function has no 'await' expression."]
},
{
code: "({ async foo() { doSomething() } })",
errors: ["Async method 'foo' has no 'await' expression."]
},
{
code: "class A { async foo() { doSomething() } }",
errors: ["Async method 'foo' has no 'await' expression."]
},
{
code: "(class { async foo() { doSomething() } })",
errors: ["Async method 'foo' has no 'await' expression."]
},
{
code: "(class { async ''() { doSomething() } })",
errors: ["Async method '' has no 'await' expression."]
},
{
code: "async function foo() { async () => { await doSomething() } }",
errors: ["Async function 'foo' has no 'await' expression."]
},
{
code: "async function foo() { await async () => { doSomething() } }",
errors: ["Async arrow function has no 'await' expression."]
}
]
});