-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathwebworker-test.cjs
200 lines (183 loc) · 5.35 KB
/
webworker-test.cjs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"use strict";
/* globals markdownlintCli2, FsVirtual, QUnit */
const md009 = "# Title\n\nText \n";
const md010 = "# Title\n\n\tText\n";
const md009md010 = "# Title\n\nText\t\n";
const md047 = "# Title\n\nText";
const configNoMd010 = "{\n\"no-hard-tabs\": false\n}";
const configNoMd047 = "{\n\"single-trailing-newline\": false\n}";
const files = [
[ "/file.md", md009md010 ],
[ "/file-two.md", md047 ],
[ "/.gitignore", "dir*" ],
[ "/package.json", `{\n"markdownlint-cli2": {\n"config": ${configNoMd047},\n"customRules": [],\n"markdownItPlugins": []\n}\n}` ],
[ "/dir1/file.md", md009md010 ],
[ "/dir1/.markdownlint.json", configNoMd010 ],
[ "/dir2/file.md", md009md010 ],
[ "/dir2/.markdownlint-cli2.jsonc", `{\n"config":${configNoMd010}\n}` ],
[ "/dir3/file.md", md009md010 ],
[ "/dir3/.markdownlint.json", "{\n\"extends\": \"./extended.json\"\n}" ],
[ "/dir3/extended.json", configNoMd010 ],
[ "/dir4/file.md", md009 ],
[ "/dir5/file.md", md009md010 ],
[ "/dir5/.markdownlint-cli2.yaml", `config:\n extends: ./extended.json\n` ],
[ "/dir5/extended.json", configNoMd010 ],
[ "/dir6/skip.md", md009md010 ],
[ "/dir6/.markdownlint-cli2.jsonc", `{\n"ignores":["skip.md"]\n}` ]
];
const outputFormatterLengthIs = (assert, length) => (options) => {
const { results } = options;
assert.equal(Object.keys(results).length, length);
};
QUnit.test("script loads", (assert) => {
assert.expect(1);
assert.ok(markdownlintCli2);
});
QUnit.test("empty call to main()", (assert) => {
assert.expect(1);
assert.ok(markdownlintCli2.main({
"fs": new FsVirtual(files)
}));
});
QUnit.test("unsaved", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [],
"nonFileContents": {
"untitled-1": md009md010
},
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 2) ] ]
}
});
});
QUnit.test("unsaved, empty", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [],
"nonFileContents": {
"untitled-1": ""
},
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 0) ] ]
}
});
});
QUnit.test("file, no configuration", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ ":/file.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 2) ] ]
}
});
});
QUnit.test("file, no configuration, edits", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ ":/file.md" ],
"fileContents": {
"/file.md": md009
},
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 1) ] ]
}
});
});
QUnit.test("file, .markdownlint.json", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ ":/dir1/file.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 1) ] ]
}
});
});
QUnit.test("file, .markdownlint.json, edits", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ ":/dir1/file.md" ],
"fileContents": {
"/dir1/file.md": md010
},
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 0) ] ]
}
});
});
QUnit.test("file, .markdownlint.json, extends", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ ":/dir3/file.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 1) ] ]
}
});
});
QUnit.test("file, .markdownlint-cli2.jsonc", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ ":/dir2/file.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 1) ] ]
}
});
});
QUnit.test("file, fix", (assert) => {
assert.expect(3);
const fsVirtual = new FsVirtual(files);
return markdownlintCli2.main({
"fs": fsVirtual,
"argv": [ ":/dir4/file.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 1) ] ]
}
}).
then(() => markdownlintCli2.main({
"fs": fsVirtual,
"argv": [ ":/dir4/file.md" ],
"optionsOverride": {
"fix": true,
"outputFormatters": [ [ outputFormatterLengthIs(assert, 0) ] ]
}
})).
then(() => markdownlintCli2.main({
"fs": fsVirtual,
"argv": [ ":/dir4/file.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 0) ] ]
}
}));
});
QUnit.test("workspace", (assert) => {
assert.expect(1);
return markdownlintCli2.main({
"fs": new FsVirtual(files),
"argv": [ "**/*.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 7) ] ]
}
});
});
QUnit.test("workspace, gitignore (unsupported)", (assert) => {
assert.expect(1);
const filesWithGitignore = [
...files,
[ "/.markdownlint-cli2.jsonc", `{\n"gitignore":true\n}` ]
];
return markdownlintCli2.main({
"fs": new FsVirtual(filesWithGitignore),
"argv": [ "**/*.md" ],
"optionsOverride": {
"outputFormatters": [ [ outputFormatterLengthIs(assert, 8) ] ]
}
});
});