Skip to content

Commit

Permalink
Move tests into test/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Dec 24, 2023
1 parent cf7d5f3 commit d77a84a
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 44 deletions.
7 changes: 7 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['node_modules', '_fixtures.ts', 'test-d'],

// NOTE: These alias mapping must exactly match the mappings from the "paths"
// setting in our tsconfig
moduleNameMapper: {
'^~$': '<rootDir>/src',
'^~/(.*)$': '<rootDir>/src/$1',
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"actually-prepublish": "echo \"\\n\\nPlease run \\`bin/publish.sh <options>\\` instead.\\n\\n\" && exit 2",
"build": "tsup && cp dist/format.js . && cp dist/result.js .",
"docs": "cog -cr docs/*.md",
"lint": "eslint --color --report-unused-disable-directives src/**/*.ts && prettier --list-different src test-d",
"lint": "eslint --color --report-unused-disable-directives src/**/*.ts test/**/*.ts && prettier --list-different src/ test/ test-d/",
"lint:docs": "cog -c --check docs/*.md || (npm run docs; git diff; echo 'Error: docs not up-to-date, please re-run \"npm docs\" to update them.' && exit 1)",
"lint:package": "publint --strict && attw --pack",
"format": "eslint --report-unused-disable-directives --fix src && prettier --write 'src/**/*.js'",
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/Decoder.test.ts → test/Decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { annotate } from '../annotate';
import { formatInline, formatShort } from '../format';
import { number } from '../lib/numbers';
import { pojo } from '../lib/objects';
import { string } from '../lib/strings';
import { annotate } from '~/annotate';
import { formatInline, formatShort } from '~/format';
import { number } from '~/lib/numbers';
import { pojo } from '~/lib/objects';
import { string } from '~/lib/strings';

describe('.decode', () => {
// .decode() is tested implicitly because it's used _everywhere_
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/__tests__/_utils.test.ts → test/_utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax */

import { indent, subtract } from '../_utils';
import type { Scalar } from '../Decoder';
import { indent, subtract } from '~/_utils';
import type { Scalar } from '~/Decoder';

describe('subtract', () => {
const exampleSets: Set<Scalar>[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/annotate.test.ts → test/annotate.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { annotate, array, circularRef, merge, object, scalar } from '../annotate';
import { annotate, array, circularRef, merge, object, scalar } from '~/annotate';

describe('parsing (scalars)', () => {
it('strings', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/__tests__/arrays.test.ts → test/arrays.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { array, nonEmptyArray, set, tuple } from '../arrays';
import { number } from '../numbers';
import { object } from '../objects';
import { string } from '../strings';
import { array, nonEmptyArray, set, tuple } from '~/lib/arrays';
import { number } from '~/lib/numbers';
import { object } from '~/lib/objects';
import { string } from '~/lib/strings';

describe('array', () => {
it('empty array', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/basics.test.ts → test/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
nullable,
optional,
undefined_,
} from '../basics';
} from '~/lib/basics';
import { INPUTS } from './_fixtures';
import { partition } from 'itertools';
import { string } from '../strings';
import { string } from '~/lib/strings';

describe('null_', () => {
const decoder = null_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-restricted-syntax */

import { boolean, numericBoolean, truthy } from '../booleans';
import { boolean, numericBoolean, truthy } from '~/lib/booleans';
import { INPUTS } from './_fixtures';
import { partition } from 'itertools';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/dates.test.ts → test/dates.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-restricted-syntax */

import { date, iso8601 } from '../dates';
import { date, iso8601 } from '~/lib/dates';
import { INPUTS } from './_fixtures';
import { partition } from 'itertools';

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/format.test.ts → test/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { __private_annotate, annotate } from '../annotate';
import { formatInline, formatShort } from '../format';
import { __private_annotate, annotate } from '~/annotate';
import { formatInline, formatShort } from '~/format';

const whitespace_re = /^\s*$/;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/json.test.ts → test/json.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, jsonArray, jsonObject } from '../json';
import { json, jsonArray, jsonObject } from '~/lib/json';

describe('decoder', () => {
const decoder = json;
Expand Down
8 changes: 7 additions & 1 deletion src/lib/__tests__/numbers.test.ts → test/numbers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable no-restricted-syntax */

import { anyNumber, integer, number, positiveInteger, positiveNumber } from '../numbers';
import {
anyNumber,
integer,
number,
positiveInteger,
positiveNumber,
} from '~/lib/numbers';
import { INPUTS } from './_fixtures';
import { partition } from 'itertools';

Expand Down
8 changes: 4 additions & 4 deletions src/lib/__tests__/objects.test.ts → test/objects.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dict, exact, inexact, mapping, object, pojo } from '../objects';
import { hardcoded, optional, unknown } from '../basics';
import { number } from '../numbers';
import { string } from '../strings';
import { dict, exact, inexact, mapping, object, pojo } from '~/lib/objects';
import { hardcoded, optional, unknown } from '~/lib/basics';
import { number } from '~/lib/numbers';
import { string } from '~/lib/strings';

describe('objects', () => {
it('decodes objects and fields', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/result.test.ts → test/result.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { err, ok } from '../result';
import { err, ok } from '~/result';

describe('Result', () => {
const r1 = ok(42);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/strings.test.ts → test/strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
uuid,
uuidv1,
uuidv4,
} from '../strings';
} from '~/lib/strings';
import { INPUTS } from './_fixtures';
import { partition } from 'itertools';

Expand Down
16 changes: 8 additions & 8 deletions src/lib/__tests__/unions.test.ts → test/unions.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-restricted-syntax */

import { boolean } from '../booleans';
import { constant, undefined_ } from '../basics';
import { either, oneOf } from '../unions';
import { boolean } from '~/lib/booleans';
import { constant, undefined_ } from '~/lib/basics';
import { either, oneOf } from '~/lib/unions';
import { INPUTS } from './_fixtures';
import { number } from '../numbers';
import { object } from '../objects';
import { number } from '~/lib/numbers';
import { object } from '~/lib/objects';
import { partition } from 'itertools';
import { regex, string } from '../strings';
import { taggedUnion } from '../unions';
import type { Decoder } from '../../Decoder';
import { regex, string } from '~/lib/strings';
import { taggedUnion } from '~/lib/unions';
import type { Decoder } from '~/Decoder';

describe('either', () => {
const stringOrBooleanDecoder = either(string, boolean);
Expand Down
16 changes: 8 additions & 8 deletions src/lib/__tests__/utilities.test.ts → test/utilities.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-restricted-syntax */

import { array } from '../arrays';
import { constant } from '../basics';
import { fail, instanceOf, lazy, never, prep } from '../utilities';
import { array } from '~/lib/arrays';
import { constant } from '~/lib/basics';
import { fail, instanceOf, lazy, never, prep } from '~/lib/utilities';
import { INPUTS } from './_fixtures';
import { number } from '../numbers';
import { object } from '../objects';
import { optional } from '../basics';
import { number } from '~/lib/numbers';
import { object } from '~/lib/objects';
import { optional } from '~/lib/basics';
import { partition } from 'itertools';
import { string } from '../strings';
import type { Decoder } from '../../Decoder';
import { string } from '~/lib/strings';
import type { Decoder } from '~/Decoder';

describe('instanceOf', () => {
const errorDecoder = instanceOf(Error);
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
// "noUncheckedIndexedAccess": true,
"noUncheckedIndexedAccess": false,
"noUnusedLocals": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"paths": {
"~": ["./src"],
"~/*": ["./src/*"]
}
},
"include": ["src", "test"],
"exclude": ["node_modules", "dist"]
Expand Down

0 comments on commit d77a84a

Please sign in to comment.