mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
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:
@@ -1,13 +1,13 @@
|
||||
const path = require('path');
|
||||
|
||||
const lint = require('.');
|
||||
import path from 'path';
|
||||
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
|
||||
import lint from '.';
|
||||
|
||||
describe('markdown linter', () => {
|
||||
let good = { path: path.join(__dirname, './fixtures/good.md') };
|
||||
let badYML = { path: path.join(__dirname, './fixtures/badYML.md') };
|
||||
let badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') };
|
||||
const good = { path: path.join(__dirname, './fixtures/good.md') };
|
||||
const badYML = { path: path.join(__dirname, './fixtures/badYML.md') };
|
||||
const badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') };
|
||||
beforeEach(() => {
|
||||
console.log = jest.fn();
|
||||
console.log = vi.fn();
|
||||
// the linter signals that a file failed by setting
|
||||
// exitCode to 1, so it needs (re)setting to 0
|
||||
process.exitCode = 0;
|
||||
@@ -16,40 +16,29 @@ describe('markdown linter', () => {
|
||||
process.exitCode = 0;
|
||||
});
|
||||
|
||||
it('should pass `good` markdown', done => {
|
||||
function callback() {
|
||||
expect(process.exitCode).toBe(0);
|
||||
done();
|
||||
}
|
||||
lint(good, callback);
|
||||
it('should pass `good` markdown', async () => {
|
||||
await new Promise(resolve => lint(good, resolve));
|
||||
expect(process.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
it('should fail invalid YML blocks', done => {
|
||||
function callback() {
|
||||
expect(process.exitCode).toBe(1);
|
||||
done();
|
||||
}
|
||||
lint(badYML, callback);
|
||||
it('should fail invalid YML blocks', async () => {
|
||||
await new Promise(resolve => lint(badYML, resolve));
|
||||
expect(process.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it('should fail when code fences are not surrounded by newlines', done => {
|
||||
function callback() {
|
||||
expect(process.exitCode).toBe(1);
|
||||
done();
|
||||
}
|
||||
lint(badFencing, callback);
|
||||
it('should fail when code fences are not surrounded by newlines', async () => {
|
||||
await new Promise(resolve => lint(badFencing, resolve));
|
||||
expect(process.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it('should write to the console describing the problem', done => {
|
||||
function callback() {
|
||||
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"]';
|
||||
expect(console.log.mock.calls.length).toBe(1);
|
||||
expect(console.log.mock.calls[0][0]).toEqual(
|
||||
expect.stringContaining(expected)
|
||||
);
|
||||
done();
|
||||
}
|
||||
lint(badYML, callback);
|
||||
it('should write to the console describing the problem', async () => {
|
||||
await new Promise(resolve => lint(badYML, resolve));
|
||||
|
||||
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"]';
|
||||
expect(console.log.mock.calls.length).toBe(1);
|
||||
expect(console.log.mock.calls[0][0]).toEqual(
|
||||
expect.stringContaining(expected)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user