chore(tools): migrate scripts/lint test to vitest (#62265)

Co-authored-by: Sem Bauke <sem@freecodecamp.org>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Huyen Nguyen
2025-09-19 14:46:06 +07:00
committed by GitHub
parent 3a2e0b112a
commit 68614b43a9
6 changed files with 61 additions and 37 deletions
+1
View File
@@ -6,6 +6,7 @@ module.exports = {
'tools/challenge-helper-scripts/', 'tools/challenge-helper-scripts/',
'tools/challenge-parser/', 'tools/challenge-parser/',
'tools/scripts/build/', 'tools/scripts/build/',
'tools/scripts/lint/',
'curriculum', 'curriculum',
'client' 'client'
], ],
+1 -1
View File
@@ -74,13 +74,13 @@
"test:api": "cd api && pnpm test", "test:api": "cd api && pnpm test",
"test:tools:challenge-helper-scripts": "cd ./tools/challenge-helper-scripts && pnpm test run", "test:tools:challenge-helper-scripts": "cd ./tools/challenge-helper-scripts && pnpm test run",
"test:tools:scripts-build": "cd ./tools/scripts/build && pnpm test run", "test:tools:scripts-build": "cd ./tools/scripts/build && pnpm test run",
"test:tools:scripts-lint": "cd ./tools/scripts/lint && pnpm test run",
"test:tools:challenge-parser": "cd ./tools/challenge-parser && pnpm test run", "test:tools:challenge-parser": "cd ./tools/challenge-parser && pnpm test run",
"test:curriculum:content": "cd ./curriculum && pnpm test run", "test:curriculum:content": "cd ./curriculum && pnpm test run",
"test:curriculum:tooling": "cd ./curriculum && pnpm vitest run", "test:curriculum:tooling": "cd ./curriculum && pnpm vitest run",
"test-curriculum-full-output": "cd ./curriculum && pnpm run test:full-output run", "test-curriculum-full-output": "cd ./curriculum && pnpm run test:full-output run",
"test:client": "cd ./client && pnpm test run", "test:client": "cd ./client && pnpm test run",
"test-config": "jest config", "test-config": "jest config",
"test-tools": "jest tools",
"test-utils": "jest utils", "test-utils": "jest utils",
"prepare": "husky", "prepare": "husky",
"playwright:run": "playwright test", "playwright:run": "playwright test",
+9
View File
@@ -1079,6 +1079,15 @@ importers:
specifier: ^3.2.4 specifier: ^3.2.4
version: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jsdom@26.1.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0) version: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jsdom@26.1.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0)
tools/scripts/lint:
devDependencies:
'@vitest/ui':
specifier: ^3.2.4
version: 3.2.4(vitest@3.2.4)
vitest:
specifier: ^3.2.4
version: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jsdom@26.1.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0)
tools/scripts/seed: tools/scripts/seed:
devDependencies: devDependencies:
debug: debug:
+1
View File
@@ -11,6 +11,7 @@ packages:
- 'tools/crowdin' - 'tools/crowdin'
- 'tools/daily-challenges' - 'tools/daily-challenges'
- 'tools/scripts/build' - 'tools/scripts/build'
- 'tools/scripts/lint'
- 'tools/scripts/seed' - 'tools/scripts/seed'
- 'tools/scripts/seed-exams' - 'tools/scripts/seed-exams'
+16 -27
View File
@@ -1,13 +1,13 @@
const path = require('path'); import path from 'path';
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
const lint = require('.'); import lint from '.';
describe('markdown linter', () => { describe('markdown linter', () => {
let good = { path: path.join(__dirname, './fixtures/good.md') }; const good = { path: path.join(__dirname, './fixtures/good.md') };
let badYML = { path: path.join(__dirname, './fixtures/badYML.md') }; const badYML = { path: path.join(__dirname, './fixtures/badYML.md') };
let badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') }; const badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') };
beforeEach(() => { beforeEach(() => {
console.log = jest.fn(); console.log = vi.fn();
// the linter signals that a file failed by setting // the linter signals that a file failed by setting
// exitCode to 1, so it needs (re)setting to 0 // exitCode to 1, so it needs (re)setting to 0
process.exitCode = 0; process.exitCode = 0;
@@ -16,40 +16,29 @@ describe('markdown linter', () => {
process.exitCode = 0; process.exitCode = 0;
}); });
it('should pass `good` markdown', done => { it('should pass `good` markdown', async () => {
function callback() { await new Promise(resolve => lint(good, resolve));
expect(process.exitCode).toBe(0); expect(process.exitCode).toBe(0);
done();
}
lint(good, callback);
}); });
it('should fail invalid YML blocks', done => { it('should fail invalid YML blocks', async () => {
function callback() { await new Promise(resolve => lint(badYML, resolve));
expect(process.exitCode).toBe(1); expect(process.exitCode).toBe(1);
done();
}
lint(badYML, callback);
}); });
it('should fail when code fences are not surrounded by newlines', done => { it('should fail when code fences are not surrounded by newlines', async () => {
function callback() { await new Promise(resolve => lint(badFencing, resolve));
expect(process.exitCode).toBe(1); expect(process.exitCode).toBe(1);
done();
}
lint(badFencing, callback);
}); });
it('should write to the console describing the problem', done => { it('should write to the console describing the problem', async () => {
function callback() { await new Promise(resolve => lint(badYML, resolve));
const expected = const expected =
'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n testString: testString\n ^] [Context: "```yml"]'; 'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n testString: testString\n ^] [Context: "```yml"]';
expect(console.log.mock.calls.length).toBe(1); expect(console.log.mock.calls.length).toBe(1);
expect(console.log.mock.calls[0][0]).toEqual( expect(console.log.mock.calls[0][0]).toEqual(
expect.stringContaining(expected) expect.stringContaining(expected)
); );
done();
}
lint(badYML, callback);
}); });
}); });
+24
View File
@@ -0,0 +1,24 @@
{
"name": "@freecodecamp/scripts-lint",
"version": "0.0.1",
"description": "The freeCodeCamp.org open-source codebase and curriculum",
"license": "BSD-3-Clause",
"private": true,
"main": "none",
"repository": {
"type": "git",
"url": "git+https://github.com/freeCodeCamp/freeCodeCamp.git"
},
"bugs": {
"url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
},
"homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme",
"author": "freeCodeCamp <team@freecodecamp.org>",
"scripts": {
"test": "vitest"
},
"devDependencies": {
"@vitest/ui": "^3.2.4",
"vitest": "^3.2.4"
}
}