Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/.env
/src/graphql
/.eslintcache
/.tsbuildinfo
40 changes: 40 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = [
'src/graphql/generated/**',
'bin/**',
'coverage/**',
'.tsbuildinfo/**',
],
},

Expand Down Expand Up @@ -57,9 +58,48 @@ module.exports = [
...js.configs.recommended,
},

// Jest config files - use separate tsconfig that allows .ts extensions
{
files: ['jest.config*.ts'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser: tsparser,
parserOptions: {
project: './tsconfig.jest-config.json',
},
globals: nodeGlobals,
},
plugins: {
'@typescript-eslint': tseslint,
import: importPlugin,
},
rules: {
...js.configs.recommended.rules,
...tseslint.configs.recommended.rules,
'import/order': [
'error',
{
alphabetize: { order: 'asc' },
'newlines-between': 'never',
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
},
],
'import/no-duplicates': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'no-unused-vars': 'off',
},
},

// TypeScript files
{
files: ['**/*.ts'],
ignores: ['jest.config*.ts'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
Expand Down
8 changes: 6 additions & 2 deletions jest.config.all.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import baseConfig from './jest.config';
/**
* @jest-config-loader-options {"compilerOptions":{"allowImportingTsExtensions":true}}
*/
import type { Config } from 'jest';
import baseConfig from './jest.config.ts';

const config = {
const config: Config = {
...baseConfig,
modulePathIgnorePatterns: [],
};
Expand Down
8 changes: 6 additions & 2 deletions jest.config.mutation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import baseConfig from './jest.config';
/**
* @jest-config-loader-options {"compilerOptions":{"allowImportingTsExtensions":true}}
*/
import type { Config } from 'jest';
import baseConfig from './jest.config.ts';

const config = {
const config: Config = {
...baseConfig,

// only include "mutation" tests that cannot run on in parallel (like they are on CI) because they mutate shared state
Expand Down
8 changes: 6 additions & 2 deletions jest.config.private.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import baseConfig from './jest.config';
/**
* @jest-config-loader-options {"compilerOptions":{"allowImportingTsExtensions":true}}
*/
import type { Config } from 'jest';
import baseConfig from './jest.config.ts';

const config = {
const config: Config = {
...baseConfig,

// only include (private) tests that cannot run on CI because they require credentials and thus exclude external contributors
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.jest-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowImportingTsExtensions": true,
"composite": true,
"emitDeclarationOnly": true,
"outDir": "./.tsbuildinfo/jest-config"
},
"include": ["jest.config*.ts"],
"exclude": []
}
9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"references": [
{ "path": "./tsconfig.jest-config.json" }
],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use project references for jest configs? Why not have a separate tsconfig, like the one for eslint https://github.com/sorenlouv/backport/blob/main/tsconfig.eslint.json?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsconfig.jest-config.json is not a standard path for tsconfig lsps to pickup. So IDEs and editors just don't see it. With eslint config it consumes the custom path of tsconfig directly but with these custom jest-config ts files there is nowhere to link the two together. So reference paths is a natural way to split it while exposing a single entry point for discovery by whatever client.

"plugins": [
{
"name": "@0no-co/graphqlsp",
"schema": "./schema.graphql"
}
],
"include": ["src/**/*"],
"exclude": ["src/graphql/generated/graphql.ts"],
"exclude": ["src/graphql/generated/graphql.ts", "jest.config*.ts"],
"compilerOptions": {
"declaration": true,
"target": "ES2021",
"lib": [
"ES2021",
"ES2021",
"DOM" // needed by wonka
],
"module": "CommonJS",
Expand All @@ -29,6 +32,6 @@
"esModuleInterop": true,
"useUnknownInCatchVariables": true,
"sourceMap": true,
"resolveJsonModule": true,
"resolveJsonModule": true
}
}