Skip to content

Commit

Permalink
chore: migrate to mocha and eslint 9
Browse files Browse the repository at this point in the history
Migrates from Jest to mocha and node's own `assert` library.

Also updates ESLint to 9.x and bumps TSESLint to do the same.
  • Loading branch information
43081j committed Sep 19, 2024
1 parent be4ac72 commit 6408ba0
Show file tree
Hide file tree
Showing 21 changed files with 4,266 additions and 7,866 deletions.
5 changes: 5 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"reporter": ["lcov"],
"include": ["packages/*/lib/**/*.ts"],
"exclude": []
}
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

59 changes: 0 additions & 59 deletions .eslintrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/nodejs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ jobs:
- run: npm ci
- run: npm run build --if-present

- name: Run Jest
- name: Run unit tests
run: npm run unit-tests
if: matrix.node != env.NODE_COV

- name: Run Jest with coverage
run: npm run unit-tests -- --coverage
- name: Run unit tests with coverage
run: npm run unit-tests-coverage
if: matrix.node == env.NODE_COV

- name: Run Coveralls
Expand Down
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": "ts-node/register",
"loader": "ts-node/esm",
"extensions": ["ts"],
"spec": ["**/*.test.ts"],
"watch-files": ["packages/*/lib"]
}
2 changes: 2 additions & 0 deletions bench/memory/sax-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import memwatch from '@airbnb/node-memwatch';
import { SAXParser } from '../../packages/parse5-sax-parser/dist/index.js';
import { finished } from 'parse5-test-utils/dist/common.js';

/* eslint-disable no-console */

const heapDiffMeasurement = new memwatch.HeapDiff();

let maxMemUsage = 0;
Expand Down
2 changes: 2 additions & 0 deletions bench/perf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as parse5 from '../../packages/parse5/dist/index.js';
import { ParserStream as parse5Stream } from '../../packages/parse5-parser-stream/dist/index.js';
import * as parse5Upstream from 'parse5';

/* eslint-disable no-console */

const hugePagePath = new URL('../../test/data/huge-page/huge-page.html', import.meta.url);
const treeConstructionPath = new URL('../../test/data/html5lib-tests/tree-construction', import.meta.url);
const saxPath = new URL('../../test/data/sax/', import.meta.url);
Expand Down
77 changes: 77 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import eslintjs from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import { configs as tseslintConfigs } from 'typescript-eslint';
import globals from 'globals';

const { configs: eslintConfigs } = eslintjs;

const sourceFiles = ['bench/**/*.js', 'scripts/**/*.ts', 'packages/*/lib/**/*.ts'];
const testFiles = ['test/**/*.{ts,js}'];
const ignoreFiles = [
'test/data/html5lib-tests',
'test/data/html5lib-tests-fork',
'packages/*/dist/',
'test/dist/',
'docs/build/',
];
const allFiles = [...sourceFiles, ...testFiles];

export default [
{
files: allFiles,
},
{
ignores: ignoreFiles,
},
{
languageOptions: {
globals: {
...globals.nodeBuiltin,
...globals.es2019,
},
},
},
eslintConfigs.recommended,
...tseslintConfigs.recommended,
{
rules: {
'no-console': 'error',
curly: ['error', 'all'],
'prefer-arrow-callback': 'error',
'one-var': ['error', 'never'],
'no-var': 'error',
'prefer-const': 'error',
'object-shorthand': 'error',
'prefer-destructuring': [
'error',
{
object: true,
array: false,
},
],
'prefer-template': 'error',
'arrow-body-style': ['error', 'as-needed'],
},
},
{
files: testFiles,
languageOptions: {
globals: {
...globals.mocha,
},
},
},
{
files: ['**/*.ts'],
rules: {
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/consistent-type-imports': 'error',

'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
},
},
eslintConfigPrettier,
];
Loading

0 comments on commit 6408ba0

Please sign in to comment.