Skip to content

Commit

Permalink
refactor: bundle code using tsup and reformat internals
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 6, 2023
1 parent 7202805 commit b34c6b4
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 38 deletions.
12 changes: 8 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
* file that was distributed with this source code.
*/

import './src/types/extended.js'

import type { PluginFn } from '@japa/runner/types'
import { Test, TestContext } from '@japa/runner/core'

import { Assert } from './src/assert/main.js'
import type { PluginConfig } from './src/types/main.js'
import { Assert } from './src/assert.js'
import type { PluginConfig } from './src/types.js'

declare module '@japa/runner/core' {
interface TestContext {
assert: Assert
}
}

/**
* Plugin for "@japa/runner"
Expand Down
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@
"main": "./build/index.js",
"type": "module",
"files": [
"index.ts",
"src",
"build/src",
"build/index.d.ts",
"build/index.js",
"build/index.d.ts.map"
"build",
"!build/tests",
"!build/tests_helpers"
],
"exports": {
".": "./build/index.js",
"./types": "./build/src/types/main.js"
"./types": "./build/src/types.js"
},
"scripts": {
"pretest": "npm run lint && npm run typecheck",
"test": "c8 npm run quick:test",
"quick:test": "cross-env NODE_NO_WARNINGS=1 glob -c \"node --enable-source-maps --loader=ts-node/esm --test\" \"test/**/*.spec.ts\"",
"clean": "del-cli build",
"compile": "npm run lint && npm run clean && tsc",
"precompile": "npm run lint && npm run clean",
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
"build": "npm run compile",
"release": "np --message=\"chore(release): %s\"",
"release": "np",
"version": "npm run build",
"prepublishOnly": "npm run build",
"lint": "eslint . --ext=.ts",
Expand Down Expand Up @@ -56,6 +54,7 @@
"np": "^8.0.4",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"dependencies": {
Expand Down Expand Up @@ -113,5 +112,17 @@
},
"directories": {
"test": "tests"
},
"tsup": {
"entry": [
"./index.ts",
"./src/types.ts"
],
"outDir": "./build",
"clean": true,
"format": "esm",
"dts": false,
"sourcemap": true,
"target": "esnext"
}
}
2 changes: 1 addition & 1 deletion src/assert/main.ts → src/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { chaiPlugin } from 'api-contract-validator'
import { assert, Assertion, AssertionError, use, expect } from 'chai'

import { subsetCompare } from './utils.js'
import type { AssertContract, ChaiAssert } from '../types/main.js'
import type { AssertContract, ChaiAssert } from './types.js'

/**
* The Assert class is derived from chai.assert to allow support
Expand Down
File renamed without changes.
16 changes: 0 additions & 16 deletions src/types/extended.ts

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions test/assert/assert.spec.ts → tests/assert/assert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import { test } from 'node:test'
import { DateTime } from 'luxon'
import { Assert } from '../../src/assert/main.js'
import { expectError, expectAsyncError } from '../../test_helpers/index.js'
import { Assert } from '../../src/assert.js'
import { expectError, expectAsyncError } from '../../tests_helpers/index.js'

/**
* Tests in this file is a copy of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { before, test } from 'node:test'
import { Assert } from '../../src/assert/main.js'
import { expectError } from '../../test_helpers/index.js'
import { Assert } from '../../src/assert.js'
import { expectError } from '../../tests_helpers/index.js'

/**
* Tests are copied from https://raw.githubusercontent.com/debitoor/chai-subset/master/test/unit/chai-subset.spec.js.
Expand Down
4 changes: 2 additions & 2 deletions test/assert/openapi.spec.ts → tests/assert/openapi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { test } from 'node:test'
import { Assert } from '../../src/assert/main.js'
import { expectError } from '../../test_helpers/index.js'
import { Assert } from '../../src/assert.js'
import { expectError } from '../../tests_helpers/index.js'

Assert.registerApiSpecs([new URL('../../api-spec.json', import.meta.url)])

Expand Down
4 changes: 2 additions & 2 deletions test/plugin.spec.ts → tests/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { assert as chaiAssert } from 'chai'
import { TestContext, Test, Emitter, Refiner } from '@japa/runner/core'

import { assert } from '../index.js'
import { Assert } from '../src/assert/main.js'
import { wrapAssertions } from '../test_helpers/index.js'
import { Assert } from '../src/assert.js'
import { wrapAssertions } from '../tests_helpers/index.js'

test.describe('Plugin', () => {
test('add assert property to test context', async () => {
Expand Down
File renamed without changes.

0 comments on commit b34c6b4

Please sign in to comment.