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: 0 additions & 1 deletion .eslintignore

This file was deleted.

14 changes: 7 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
"jest": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"import"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"plugins": [
"import"
],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"rules": {
"linebreak-style": ["error", "unix"],
"no-empty": 1,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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
52 changes: 25 additions & 27 deletions jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const process = require('process');
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');
import path from 'node:path';
import url from 'node:url';
import os from 'node:os';
import process from 'node:process';
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
if ((process.env.PK_TEST_PLATFORM != null) !== (process.env.PK_TEST_COMMAND != null)) throw Error('Both PK_TEST_PLATFORM and PK_TEST_COMMAND must be set together.')
const globals = {
// Absolute directory to the project root
projectDir: __dirname,
projectDir: projectPath,
// Absolute directory to the test root
testDir: path.join(__dirname, 'tests'),
// Default global data directory
dataDir: fs.mkdtempSync(
path.join(os.tmpdir(), 'polykey-test-global-'),
),
testDir: path.join(projectPath, 'tests'),
// Default asynchronous test timeout
defaultTimeout: 20000,
failedConnectionTimeout: 50000,
Expand All @@ -31,10 +23,11 @@ const globals = {

// The `globalSetup` and `globalTeardown` cannot access the `globals`
// They run in their own process context
// They can receive process environment
// They can however receive the process environment
// Use `process.env` to set variables
process.env['GLOBAL_DATA_DIR'] = globals.dataDir;

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

export default config;
2 changes: 1 addition & 1 deletion npmDepsHash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256-LHQ8nB8ewWjKMgdkS1oguQKaFk1IsAroYdZ21Z7bnME=
sha256-HhXB5SIRl0Z8RUGozF7NHcaOQsvMmUG90iZlUBcbyng=
Loading