1
1
mirror of https://github.com/theoludwig/html-w3c-validator.git synced 2025-05-21 23:21:29 +02:00

feat: usage of ESM modules imports (instead of CommonJS)

This commit is contained in:
Divlo
2022-04-06 19:59:31 +02:00
parent e032bbe637
commit e762c0fad5
23 changed files with 9357 additions and 27618 deletions

View File

@ -1,26 +1,21 @@
import path from 'node:path'
import execa from 'execa'
import tap from 'tap'
import { execa } from 'execa'
import { cli } from '../cli.js'
import { HTMLValidatorCommand } from '../HTMLValidatorCommand.js'
describe('html-w3c-validator', () => {
afterEach(() => {
jest.clearAllMocks()
})
it('should be instance of the command', () => {
await tap.test('html-w3c-validator', async (t) => {
await t.test('should be instance of the command', async (t) => {
const command = cli.process([])
expect(command).toBeInstanceOf(HTMLValidatorCommand)
t.equal(command instanceof HTMLValidatorCommand, true)
})
it('succeeds and validate the html correctly', async () => {
const examplePath = path.join(__dirname, '..', '..', 'example')
process.chdir(examplePath)
await t.test('succeeds and validate the html correctly', async (t) => {
const exampleURL = new URL('../../example', import.meta.url)
process.chdir(exampleURL.pathname)
await execa('rimraf', ['node_modules'])
await execa('npm', ['install'])
const { exitCode } = await execa('npm', ['run', 'test:html-w3c-validator'])
expect(exitCode).toEqual(0)
t.equal(exitCode, 0)
})
})

View File

@ -1 +0,0 @@
jest.setTimeout(60000)

View File

@ -1,11 +1,7 @@
import path from 'node:path'
import { Builtins, Cli } from 'clipanion'
import readPackage from 'read-pkg'
import { HTMLValidatorCommand } from './HTMLValidatorCommand.js'
const packageJSON = readPackage.sync({ cwd: path.join(__dirname, '..') })
import { packageJSON } from './packageJSON.js'
export const cli = new Cli({
binaryLabel: packageJSON.name,

View File

@ -1,12 +1,8 @@
#!/usr/bin/env node
import chalk from 'chalk'
import { Cli } from 'clipanion'
import { cli } from './cli.js'
const [, , ...arguments_] = process.argv
cli.runExit(arguments_, Cli.defaultContext).catch(() => {
console.error(chalk.red('Error occurred...'))
process.exit(1)
})
await cli.runExit(arguments_, Cli.defaultContext)

5
src/packageJSON.ts Normal file
View File

@ -0,0 +1,5 @@
import { readPackage } from 'read-pkg'
export const packageJSON = await readPackage({
cwd: new URL('..', import.meta.url)
})

View File

@ -1,29 +1,24 @@
import fsMock from 'mock-fs'
import tap from 'tap'
import { isExistingPath } from '../isExistingPath.js'
describe('utils/isExistingFile', () => {
afterEach(() => {
await tap.test('utils/isExistingPath', async (t) => {
t.afterEach(() => {
fsMock.restore()
})
it('should return true if the file exists', async () => {
fsMock(
{
'/file.txt': ''
},
{ createCwd: false }
)
expect(await isExistingPath('/file.txt')).toBeTruthy()
await t.test('should return true if the file exists', async () => {
fsMock({
'/file.txt': ''
})
t.equal(await isExistingPath('/file.txt'), true)
})
it("should return false if the file doesn't exists", async () => {
fsMock(
{
'/file.txt': ''
},
{ createCwd: false }
)
expect(await isExistingPath('/randomfile.txt')).toBeFalsy()
await t.test("should return false if the file doesn't exists", async () => {
fsMock({
'/file.txt': ''
})
t.equal(await isExistingPath('/randomfile.txt'), false)
})
})