Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"message": "Use `globalThis` instead"
}
],
"prefer-rest-params": 0,
"require-yield": 0,
"eqeqeq": ["error", "smart"],
"spaced-comment": [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run ts-node
npm run tsx
# run the tests
npm run test
# lint the source code
Expand Down
13 changes: 8 additions & 5 deletions benches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import fs from 'fs';
import path from 'path';
import url from 'url';
import si from 'systeminformation';

const dirname = url.fileURLToPath(new URL('.', import.meta.url));

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true });
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
path.join(dirname, 'results'),
);
const metricsFile = await fs.promises.open(
path.join(__dirname, 'results', 'metrics.txt'),
path.join(dirname, 'results', 'metrics.txt'),
'w',
);
let concatenating = false;
for (const resultFilename of resultFilenames) {
if (/.+_metrics\.txt$/.test(resultFilename)) {
const metricsData = await fs.promises.readFile(
path.join(__dirname, 'results', resultFilename),
path.join(dirname, 'results', resultFilename),
);
if (concatenating) {
await metricsFile.write('\n');
Expand All @@ -33,7 +36,7 @@ async function main(): Promise<void> {
system: 'model, manufacturer',
});
await fs.promises.writeFile(
path.join(__dirname, 'results', 'system.json'),
path.join(dirname, 'results', 'system.json'),
JSON.stringify(systemData, null, 2),
);
}
Expand Down
2 changes: 1 addition & 1 deletion benches/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './utils';
export * from './utils.js';
9 changes: 6 additions & 3 deletions benches/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import fs from 'fs';
import path from 'path';
import url from 'url';
import b from 'benny';
import { codeBlock } from 'common-tags';
import packageJson from '../../package.json';

const dirname = url.fileURLToPath(new URL('.', import.meta.url));

const suiteCommon = [
b.cycle(),
b.complete(),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
folder: path.join(dirname, '../results'),
version: packageJson.version,
details: true,
}),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
folder: path.join(dirname, '../results'),
version: packageJson.version,
format: 'chart.html',
}),
b.complete((summary) => {
const filePath = path.join(
__dirname,
dirname,
'../results',
summary.name + '_metrics.txt',
);
Expand Down
27 changes: 15 additions & 12 deletions jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
const path = require('path');
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');
import path from 'node:path';
import url from 'node:url';
import tsconfigJSON from './tsconfig.json' assert { type: "json" };

const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/src/',
});
const projectPath = path.dirname(url.fileURLToPath(import.meta.url));

// Global variables that are shared across the jest worker pool
// These variables must be static and serializable
const globals = {
// Absolute directory to the project root
projectDir: __dirname,
projectDir: projectPath,
// Absolute directory to the test root
testDir: path.join(__dirname, 'tests'),
testDir: path.join(projectPath, 'tests'),
// Default asynchronous test timeout
defaultTimeout: 20000,
// Timeouts rely on setTimeout which takes 32 bit numbers
Expand All @@ -24,7 +22,7 @@ const globals = {
// They can however receive the process environment
// Use `process.env` to set variables

module.exports = {
const config = {
testEnvironment: 'node',
verbose: true,
collectCoverage: false,
Expand All @@ -40,10 +38,10 @@ module.exports = {
parser: {
syntax: "typescript",
tsx: true,
decorators: compilerOptions.experimentalDecorators,
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
dynamicImport: true,
},
target: compilerOptions.target.toLowerCase(),
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
keepClassNames: true,
},
}
Expand Down Expand Up @@ -77,5 +75,10 @@ module.exports = {
'jest-extended/all',
'<rootDir>/tests/setupAfterEnv.ts'
],
moduleNameMapper: moduleNameMapper,
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
};

export default config;
Loading