@angular-eslint/test-utils 18.1.1-alpha.6 → 18.1.1-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InvalidTestCase, SuggestionOutput } from '@typescript-eslint/rule-tester';
|
|
2
2
|
/**
|
|
3
3
|
* When leveraging the convertAnnotatedSourceToFailureCase() utility, the
|
|
4
4
|
* following characters are eligible to be used in the source code of expected
|
|
@@ -9,15 +9,15 @@ import type { TSESLint } from '@typescript-eslint/utils';
|
|
|
9
9
|
* See the convertAnnotatedSourceToFailureCase() utility itself for more details.
|
|
10
10
|
*/
|
|
11
11
|
export declare const SPECIAL_UNDERLINE_CHARS: readonly ["~", "^", "#", "%", "¶", "*", "¨", "@"];
|
|
12
|
-
type MultipleErrorOptions<TMessageIds extends string> = BaseErrorOptions & {
|
|
12
|
+
type MultipleErrorOptions<TMessageIds extends string, Options extends readonly unknown[]> = BaseErrorOptions<Options> & {
|
|
13
13
|
readonly messages: readonly (Message<TMessageIds> & {
|
|
14
14
|
readonly char: (typeof SPECIAL_UNDERLINE_CHARS)[number];
|
|
15
15
|
})[];
|
|
16
16
|
};
|
|
17
|
-
type BaseErrorOptions = {
|
|
17
|
+
type BaseErrorOptions<Options> = {
|
|
18
18
|
readonly description: string;
|
|
19
19
|
readonly annotatedSource: string;
|
|
20
|
-
readonly options?:
|
|
20
|
+
readonly options?: Options;
|
|
21
21
|
readonly annotatedOutput?: string;
|
|
22
22
|
readonly annotatedOutputs?: readonly string[];
|
|
23
23
|
readonly filename?: string;
|
|
@@ -26,9 +26,9 @@ type BaseErrorOptions = {
|
|
|
26
26
|
type Message<TMessageIds extends string> = {
|
|
27
27
|
readonly messageId: TMessageIds;
|
|
28
28
|
readonly data?: Record<string, unknown>;
|
|
29
|
-
readonly suggestions?:
|
|
29
|
+
readonly suggestions?: SuggestionOutput<TMessageIds>[];
|
|
30
30
|
};
|
|
31
|
-
type SingleErrorOptions<TMessageIds extends string> = BaseErrorOptions & Message<TMessageIds>;
|
|
31
|
+
type SingleErrorOptions<TMessageIds extends string, Options extends readonly unknown[]> = BaseErrorOptions<Options> & Message<TMessageIds>;
|
|
32
32
|
/**
|
|
33
33
|
* convertAnnotatedSourceToFailureCase() provides an ergonomic way to easily write
|
|
34
34
|
* expected failure cases for ESLint rules by allowing you to directly annotate the
|
|
@@ -56,7 +56,7 @@ type SingleErrorOptions<TMessageIds extends string> = BaseErrorOptions & Message
|
|
|
56
56
|
* }),
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
|
-
export declare function convertAnnotatedSourceToFailureCase<TMessageIds extends string>(errorOptions: SingleErrorOptions<TMessageIds>):
|
|
60
|
-
export declare function convertAnnotatedSourceToFailureCase<TMessageIds extends string>(errorOptions: MultipleErrorOptions<TMessageIds>):
|
|
59
|
+
export declare function convertAnnotatedSourceToFailureCase<TMessageIds extends string, Options extends readonly unknown[]>(errorOptions: SingleErrorOptions<TMessageIds, Options>): InvalidTestCase<TMessageIds, Options>;
|
|
60
|
+
export declare function convertAnnotatedSourceToFailureCase<TMessageIds extends string, Options extends readonly unknown[]>(errorOptions: MultipleErrorOptions<TMessageIds, Options>): InvalidTestCase<TMessageIds, Options>;
|
|
61
61
|
export {};
|
|
62
62
|
//# sourceMappingURL=convert-annotated-source-to-failure-case.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-annotated-source-to-failure-case.d.ts","sourceRoot":"","sources":["../src/convert-annotated-source-to-failure-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"convert-annotated-source-to-failure-case.d.ts","sourceRoot":"","sources":["../src/convert-annotated-source-to-failure-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAEjB,MAAM,gCAAgC,CAAC;AAExC;;;;;;;;GAQG;AACH,eAAO,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,SAAS,MAAM,EAC1B,OAAO,SAAS,SAAS,OAAO,EAAE,EAElC,YAAY,EAAE,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,GACrD,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACzC,wBAAgB,mCAAmC,CACjD,WAAW,SAAS,MAAM,EAC1B,OAAO,SAAS,SAAS,OAAO,EAAE,EAElC,YAAY,EAAE,oBAAoB,CAAC,WAAW,EAAE,OAAO,CAAC,GACvD,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC"}
|
package/dist/rule-tester.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
import type { RunTests, RuleTesterConfig } from '@typescript-eslint/rule-tester';
|
|
1
2
|
import { RuleTester as TSESLintRuleTester } from '@typescript-eslint/rule-tester';
|
|
2
3
|
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
|
-
declare const VALID_PARSERS: readonly ["@angular-eslint/template-parser", "@typescript-eslint/parser"];
|
|
4
|
-
type RuleTesterConfig = Omit<TSESLint.RuleTesterConfig, 'parser'> & {
|
|
5
|
-
parser: (typeof VALID_PARSERS)[number];
|
|
6
|
-
};
|
|
7
4
|
export declare class RuleTester extends TSESLintRuleTester {
|
|
8
5
|
private filename?;
|
|
9
|
-
constructor(options
|
|
10
|
-
run<
|
|
6
|
+
constructor(options?: RuleTesterConfig);
|
|
7
|
+
run<MessageIds extends string, Options extends readonly unknown[]>(ruleName: string, rule: TSESLint.RuleModule<MessageIds, Options>, { valid, invalid }: RunTests<MessageIds, Options>): void;
|
|
11
8
|
}
|
|
12
|
-
export {};
|
|
13
9
|
//# sourceMappingURL=rule-tester.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-tester.d.ts","sourceRoot":"","sources":["../src/rule-tester.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rule-tester.d.ts","sourceRoot":"","sources":["../src/rule-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAwBzD,qBAAa,UAAW,SAAQ,kBAAkB;IAChD,OAAO,CAAC,QAAQ,CAAC,CAAc;gBAEnB,OAAO,CAAC,EAAE,gBAAgB;IAY7B,GAAG,CAAC,UAAU,SAAS,MAAM,EAAE,OAAO,SAAS,SAAS,OAAO,EAAE,EACxE,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,EAC9C,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,GAChD,IAAI;CAiCR"}
|
package/dist/rule-tester.js
CHANGED
|
@@ -34,44 +34,30 @@ function getFixturesRootDir() {
|
|
|
34
34
|
return path.join(process.cwd(), 'tests/fixtures/');
|
|
35
35
|
}
|
|
36
36
|
function isValidParser(parser) {
|
|
37
|
-
|
|
37
|
+
if (parser === require('@angular-eslint/template-parser')) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (parser === require('@typescript-eslint/parser')) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
38
44
|
}
|
|
39
45
|
class RuleTester extends rule_tester_1.RuleTester {
|
|
40
46
|
filename = '';
|
|
41
|
-
// as of eslint 6 you have to provide an absolute path to the parser
|
|
42
|
-
// but that's not as clean to type, this saves us trying to manually enforce
|
|
43
|
-
// that contributors require.resolve everything
|
|
44
47
|
constructor(options) {
|
|
45
|
-
super(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (options.parserOptions?.project) {
|
|
50
|
-
this.filename = path.join(options.parserOptions?.tsconfigRootDir ?? getFixturesRootDir(), 'file.ts');
|
|
48
|
+
super(options);
|
|
49
|
+
if (options?.languageOptions?.parserOptions?.project) {
|
|
50
|
+
this.filename = path.join(options?.languageOptions.parserOptions.tsconfigRootDir ??
|
|
51
|
+
getFixturesRootDir(), 'file.ts');
|
|
51
52
|
}
|
|
52
|
-
// make sure that the parser doesn't hold onto file handles between tests
|
|
53
|
-
// on linux (i.e. our CI env), there can be very a limited number of watch handles available
|
|
54
|
-
const afterAll = RuleTester.afterAll ?? globalThis.afterAll;
|
|
55
|
-
afterAll(() => {
|
|
56
|
-
try {
|
|
57
|
-
// instead of creating a hard dependency, just use a soft require
|
|
58
|
-
// a bit weird, but if they're using this tooling, it'll be installed
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
60
|
-
require(options.parser).clearCaches();
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// ignored
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
53
|
}
|
|
67
|
-
|
|
68
|
-
// If you don't do that at the test level, the test will fail somewhat cryptically...
|
|
69
|
-
// This is a lot more explicit
|
|
70
|
-
run(name, rule, { valid, invalid }) {
|
|
54
|
+
run(ruleName, rule, { valid, invalid }) {
|
|
71
55
|
const errorMessage = `Do not set the parser at the test level unless you want to use a parser other than ${VALID_PARSERS.join(', ')}`;
|
|
72
56
|
const parsedTests = {
|
|
73
57
|
valid: valid.map((test) => {
|
|
74
|
-
if (typeof test !== 'string' &&
|
|
58
|
+
if (typeof test !== 'string' &&
|
|
59
|
+
test.languageOptions?.parser &&
|
|
60
|
+
!isValidParser(test.languageOptions.parser)) {
|
|
75
61
|
throw Error(errorMessage);
|
|
76
62
|
}
|
|
77
63
|
return typeof test === 'string'
|
|
@@ -79,7 +65,8 @@ class RuleTester extends rule_tester_1.RuleTester {
|
|
|
79
65
|
: { ...test, filename: test.filename ?? this.filename };
|
|
80
66
|
}),
|
|
81
67
|
invalid: invalid.map((test) => {
|
|
82
|
-
if (
|
|
68
|
+
if (test.languageOptions?.parser &&
|
|
69
|
+
!isValidParser(test.languageOptions.parser)) {
|
|
83
70
|
throw Error(errorMessage);
|
|
84
71
|
}
|
|
85
72
|
return {
|
|
@@ -88,7 +75,7 @@ class RuleTester extends rule_tester_1.RuleTester {
|
|
|
88
75
|
};
|
|
89
76
|
}),
|
|
90
77
|
};
|
|
91
|
-
super.run(
|
|
78
|
+
super.run(ruleName, rule, parsedTests);
|
|
92
79
|
}
|
|
93
80
|
}
|
|
94
81
|
exports.RuleTester = RuleTester;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/test-utils",
|
|
3
|
-
"version": "18.1.1-alpha.
|
|
3
|
+
"version": "18.1.1-alpha.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@typescript-eslint/rule-tester": "^7.11.0 || ^8.0.0
|
|
21
|
-
"@typescript-eslint/utils": "^7.11.0 || ^8.0.0
|
|
20
|
+
"@typescript-eslint/rule-tester": "^7.11.0 || ^8.0.0",
|
|
21
|
+
"@typescript-eslint/utils": "^7.11.0 || ^8.0.0",
|
|
22
22
|
"eslint": "^8.57.0 || ^9.0.0",
|
|
23
23
|
"typescript": "*"
|
|
24
24
|
},
|