|
1 | | -import { describe, expect, it } from 'vitest'; |
2 | | -import fs from 'node:fs'; |
3 | | -import path from 'node:path'; |
4 | | -import packageJson from '../steps/package.json'; |
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import fs from "node:fs"; |
| 3 | +import path from "node:path"; |
| 4 | +import packageJson from "../steps/package.json"; |
5 | 5 |
|
6 | | -const STEPS_PATH = '../steps'; |
| 6 | +const STEPS_PATH = "../steps"; |
7 | 7 |
|
8 | | -const DIR_NOT_A_PROJECT = ['node_modules', 'common']; |
9 | | -const PROJECT_NOT_A_STEP = ['api']; |
| 8 | +const DIR_NOT_A_PROJECT = ["node_modules", "common"]; |
| 9 | +const PROJECT_NOT_A_STEP = ["api"]; |
10 | 10 |
|
11 | | -describe('every project should be declared in the workspace', () => { |
| 11 | +describe("every project should be declared in the workspace", () => { |
12 | 12 | const projectsDir = getProjectsDir(); |
13 | | - it.each(projectsDir)('%s', (stepDir) => { |
| 13 | + it.each(projectsDir)("%s", (stepDir) => { |
14 | 14 | expect(packageJson.workspaces.includes(stepDir)).toBeTruthy(); |
15 | 15 | }); |
16 | 16 | }); |
17 | 17 |
|
18 | | -describe('every project should have a dedicated script with the same name', () => { |
| 18 | +describe("every project should have a dedicated script with the same name", () => { |
19 | 19 | const projectsDir = getProjectsDir(); |
20 | | - it.each(projectsDir)('%s', (stepDir) => { |
| 20 | + it.each(projectsDir)("%s", (stepDir) => { |
21 | 21 | expect(packageJson.scripts[stepDir]).toBeDefined(); |
22 | 22 | }); |
23 | 23 | }); |
24 | 24 |
|
25 | 25 | describe("project's package.json name should have same name as the directory", () => { |
26 | 26 | const projectsDir = getProjectsDir(); |
27 | | - it.each(projectsDir)('%s', (stepDir) => { |
| 27 | + it.each(projectsDir)("%s", (stepDir) => { |
28 | 28 | const projectPackageJsonText = fs.readFileSync( |
29 | | - path.resolve(path.join(STEPS_PATH, stepDir, 'package.json')), |
30 | | - 'utf-8' |
| 29 | + path.resolve(path.join(STEPS_PATH, stepDir, "package.json")), |
| 30 | + "utf-8", |
31 | 31 | ); |
32 | 32 | const projectPackageJson = JSON.parse(projectPackageJsonText); |
33 | 33 | expect(projectPackageJson.name).toBe(stepDir); |
34 | 34 | }); |
35 | 35 | }); |
36 | 36 |
|
37 | | -describe('every step should have a solution project', () => { |
| 37 | +describe("every step should have a solution project", () => { |
38 | 38 | const projectsDir = getProjectsDir(); |
39 | 39 | const stepsDir = projectsDir |
40 | 40 | .filter((dir) => PROJECT_NOT_A_STEP.every((d) => !dir.endsWith(d))) |
41 | | - .filter((dir) => !dir.endsWith('-solution')); |
42 | | - it.each(stepsDir)('%s', (stepDir) => { |
43 | | - const solutionDir = stepDir + '-solution'; |
| 41 | + .filter((dir) => !dir.endsWith("-solution")); |
| 42 | + it.each(stepsDir)("%s", (stepDir) => { |
| 43 | + const solutionDir = stepDir + "-solution"; |
44 | 44 | expect(projectsDir.includes(solutionDir)).toBeTruthy(); |
45 | 45 | }); |
46 | 46 | }); |
47 | 47 |
|
48 | | -describe('every solution should have same name as step with -solution suffix', () => { |
| 48 | +describe("every solution should have same name as step with -solution suffix", () => { |
49 | 49 | const stepsDir = getProjectsDir(); |
50 | | - const solutionStepsDir = stepsDir.filter((dir) => dir.endsWith('-solution')); |
51 | | - it.each(solutionStepsDir)('%s', (solutionStepDir) => { |
52 | | - const stepDir = solutionStepDir.slice(0, -'-solution'.length); |
| 50 | + const solutionStepsDir = stepsDir.filter((dir) => dir.endsWith("-solution")); |
| 51 | + it.each(solutionStepsDir)("%s", (solutionStepDir) => { |
| 52 | + const stepDir = solutionStepDir.slice(0, -"-solution".length); |
53 | 53 | expect(stepsDir.includes(stepDir)).toBeTruthy(); |
54 | 54 | }); |
55 | 55 | }); |
56 | 56 |
|
57 | 57 | describe("solution's README.md should be identical to exercise's one", () => { |
58 | 58 | const stepsDir = getProjectsDir(); |
59 | | - const solutionStepsDir = stepsDir.filter((dir) => dir.endsWith('-solution')); |
60 | | - it.each(solutionStepsDir)('%s', (solutionStepDir) => { |
61 | | - const stepDir = solutionStepDir.slice(0, -'-solution'.length); |
62 | | - const stepReadme = fs.readFileSync(path.resolve(path.join(STEPS_PATH, stepDir, 'README.md')), 'utf-8'); |
63 | | - const solutionReadme = fs.readFileSync(path.resolve(path.join(STEPS_PATH, stepDir, 'README.md')), 'utf-8'); |
| 59 | + const solutionStepsDir = stepsDir.filter((dir) => dir.endsWith("-solution")); |
| 60 | + it.each(solutionStepsDir)("%s", (solutionStepDir) => { |
| 61 | + const stepDir = solutionStepDir.slice(0, -"-solution".length); |
| 62 | + const stepReadme = fs.readFileSync( |
| 63 | + path.resolve(path.join(STEPS_PATH, stepDir, "README.md")), |
| 64 | + "utf-8", |
| 65 | + ); |
| 66 | + const solutionReadme = fs.readFileSync( |
| 67 | + path.resolve(path.join(STEPS_PATH, solutionStepDir, "README.md")), |
| 68 | + "utf-8", |
| 69 | + ); |
64 | 70 | expect(stepReadme).toStrictEqual(solutionReadme); |
65 | 71 | }); |
66 | 72 | }); |
67 | 73 |
|
68 | | -describe('exercise README.md should point out the correct command', () => { |
| 74 | +describe("exercise README.md should point out the correct command", () => { |
69 | 75 | const projectsDir = getProjectsDir(); |
70 | 76 | const stepsDir = projectsDir |
71 | 77 | .filter((dir) => PROJECT_NOT_A_STEP.every((d) => !dir.endsWith(d))) |
72 | | - .filter((dir) => !dir.endsWith('-solution')); |
73 | | - it.each(stepsDir)('%s', (stepDir) => { |
74 | | - const stepReadme = fs.readFileSync(path.resolve(path.join(STEPS_PATH, stepDir, 'README.md')), 'utf-8'); |
| 78 | + .filter((dir) => !dir.endsWith("-solution")); |
| 79 | + it.each(stepsDir)("%s", (stepDir) => { |
| 80 | + const stepReadme = fs.readFileSync( |
| 81 | + path.resolve(path.join(STEPS_PATH, stepDir, "README.md")), |
| 82 | + "utf-8", |
| 83 | + ); |
75 | 84 | expect(stepReadme).toContain(`npm run ${stepDir}`); |
76 | 85 | }); |
77 | 86 | }); |
78 | 87 |
|
79 | | -describe('exercise README.md should have the correct title', () => { |
| 88 | +describe("exercise README.md should have the correct title", () => { |
80 | 89 | const projectsDir = getProjectsDir(); |
81 | 90 | const stepsDir = projectsDir |
82 | 91 | .filter((dir) => PROJECT_NOT_A_STEP.every((d) => !dir.endsWith(d))) |
83 | | - .filter((dir) => !dir.endsWith('-solution')); |
84 | | - it.each(stepsDir)('%s', (stepDir) => { |
85 | | - const stepReadme = fs.readFileSync(path.resolve(path.join(STEPS_PATH, stepDir, 'README.md')), 'utf-8'); |
86 | | - expect(stepReadme.split('\n')[0]).toStrictEqual(`# ${stepDir} instructions`); |
| 92 | + .filter((dir) => !dir.endsWith("-solution")); |
| 93 | + it.each(stepsDir)("%s", (stepDir) => { |
| 94 | + const stepReadme = fs.readFileSync( |
| 95 | + path.resolve(path.join(STEPS_PATH, stepDir, "README.md")), |
| 96 | + "utf-8", |
| 97 | + ); |
| 98 | + expect(stepReadme.split("\n")[0]).toStrictEqual( |
| 99 | + `# ${stepDir} instructions`, |
| 100 | + ); |
87 | 101 | }); |
88 | 102 | }); |
89 | 103 |
|
90 | 104 | function getProjectsDir() { |
91 | 105 | return fs |
92 | 106 | .readdirSync(path.resolve(STEPS_PATH)) |
93 | 107 | .filter((dir) => DIR_NOT_A_PROJECT.every((d) => !dir.endsWith(d))) |
94 | | - .filter((dir) => fs.statSync(path.resolve(path.join(STEPS_PATH, dir))).isDirectory()); |
| 108 | + .filter((dir) => |
| 109 | + fs.statSync(path.resolve(path.join(STEPS_PATH, dir))).isDirectory() |
| 110 | + ); |
95 | 111 | } |
0 commit comments