-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpackages.test.ts
More file actions
80 lines (71 loc) · 2.84 KB
/
packages.test.ts
File metadata and controls
80 lines (71 loc) · 2.84 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
import { type Dirent, existsSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import type PackageJson from './types/package-json.js';
import type VSCodeExtensionsJson from './types/vs-code-extensions-json.js';
import describeWorkspaces from './utils/describe-workspaces.js';
import mapDirectoryToPackageJson from './utils/map-directory-to-package-json.js';
import mapDirectoryToVsCodeExtensionsJson from './utils/map-directory-to-vs-code-extensions-json.js';
const DEPENDENCY_EXTENSIONS: Record<string, readonly string[]> = {
eslint: ['dbaeumer.vscode-eslint'],
publint: ['kravets.vscode-publint'],
quisido: [
'dbaeumer.vscode-eslint',
'kravets.vscode-publint',
'vitest.explorer',
],
stylelint: ['stylelint.vscode-stylelint'],
vitest: ['vitest.explorer'],
};
const FILE_EXTENSIONS: Record<string, string> = {
// '**/*.sql': 'alexcvzz.vscode-sqlite',
// '**/*.yml': 'redhat.vscode-yaml',
'.coderabbit.yml': 'coderabbit.coderabbit-vscode',
'.editorconfig': 'editorconfig.editorconfig',
'.github/copilot-instructions.md': 'github.copilot',
// '.github/workflows/*': 'github.vscode-github-actions',
};
describeWorkspaces(async (dirent: Dirent): Promise<void> => {
const packageJson: PackageJson = await mapDirectoryToPackageJson(dirent);
const isApplication: boolean = packageJson.private === true;
describe('.vscode/extensions.json', async (): Promise<void> => {
const extensions: VSCodeExtensionsJson =
await mapDirectoryToVsCodeExtensionsJson(dirent);
it('should recommend relevant extensions', (): void => {
const dependencies = new Set<string>(
Object.keys({
...packageJson.dependencies,
...packageJson.devDependencies,
}),
);
for (const [dependency, dependencyExtensions] of Object.entries(
DEPENDENCY_EXTENSIONS,
)) {
if (dependencies.has(dependency)) {
for (const dependencyExtension of dependencyExtensions) {
expect(extensions.recommendations).toContain(dependencyExtension);
}
}
}
for (const [glob, extension] of Object.entries(FILE_EXTENSIONS)) {
if (existsSync(join(dirent.parentPath, dirent.name, glob))) {
expect(extensions.recommendations).toContain(extension);
} else {
expect(extensions.recommendations).not.toContain(extension);
}
}
});
});
describe('package.json', (): void => {
it('should contain a funding field', (): void => {
expect(packageJson.funding).toEqual({
type: 'individual',
url: 'https://github.com/sponsors/quisido',
});
});
// Modules should be tested with quisido.
it.runIf(!isApplication)('should test with quisido', (): void => {
expect(packageJson.scripts?.['test']).toMatch(/^quisido test\b/u);
});
});
});