Skip to content

Commit

Permalink
Feat/migrate to node test (#352)
Browse files Browse the repository at this point in the history
* feat: migrate to node test runner

* feat: migrate to node test

* chore: removed borp

* chore: tests
  • Loading branch information
ilteoood authored Nov 8, 2024
1 parent 2d1abcc commit 118fd16
Show file tree
Hide file tree
Showing 8 changed files with 4,983 additions and 12,013 deletions.
4 changes: 0 additions & 4 deletions .taprc

This file was deleted.

16,238 changes: 4,606 additions & 11,632 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"preoas2tson": "npm run build",
"oas2tson": "./dist/esm/src/cli.js oas2tson -i ./example/openapi.yml -o ./example/output/ts",
"prepare": "husky",
"test": "tap --allow-incomplete-coverage",
"test": "node --test --loader ts-node/esm test/*.test.ts",
"build": "tsup-node",
"postbuild": "cp ./package.json ./dist/esm"
},
Expand All @@ -44,7 +44,7 @@
"desm": "^1.3.1",
"filenamify": "^6.0.0",
"fs-extra": "^11.1.1",
"json-schema-to-typescript": "^13.0.1",
"json-schema-to-typescript": "^15.0.2",
"lodash.get": "^4.4.2",
"lodash.trimstart": "^4.5.1",
"pino": "^9.3.1",
Expand All @@ -55,9 +55,10 @@
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.13",
"@types/lodash.get": "^4.4.9",
"@types/lodash.trimstart": "^4.5.9",
"@types/tap": "^15.0.11",
"@types/node": "^22.9.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"eslint": "^8.57.0",
Expand All @@ -67,7 +68,7 @@
"lint-staged": "^15.2.7",
"remark": "^15.0.1",
"remark-toc": "^9.0.0",
"tap": "^21.0.0",
"ts-node": "^10.9.2",
"tsup": "^8.2.0",
"typescript": "^5.5.3"
},
Expand Down
4 changes: 2 additions & 2 deletions src/commands/json2ts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import $RefParser from '@bcherny/json-schema-ref-parser'
import { $RefParser } from '@apidevtools/json-schema-ref-parser'
import { Command } from 'commander'
import fs from 'fs-extra'
import { compileFromFile } from 'json-schema-to-typescript'
import path from 'path'
import pino from 'pino'
import { format } from 'prettier'
import { exit } from 'process'
import type {
Json2TsArgs,
Expand All @@ -12,7 +13,6 @@ import type {
} from '../types/Json2TsOptions'
import { doNotEditText } from '../utils/do-not-edit-text.js'
import { readConfigFile } from '../utils/read-config-file.js'
import { format } from 'prettier'

const generateAndWriteTsFile = async (
schemaPath: string,
Expand Down
11 changes: 6 additions & 5 deletions test/json2ts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs-extra'
import tap from 'tap'
import { test, TestContext } from 'node:test'
import { runCommand } from '../src/commands/json2ts.js'
import { doNotEditText } from '../src/utils/do-not-edit-text.js'
import { resolveFromPackageRoot } from '../src/utils/paths.js'
Expand All @@ -9,7 +9,7 @@ const TEST_DIRECTORY = resolveFromPackageRoot('test', 'temp')
const inputPath = './test/fixtures/schemas'
const outputPath = './test/temp/types-from-json'

tap.test('json2ts runCommand', async t => {
test('json2ts runCommand', async (t: TestContext) => {
fs.ensureDirSync(TEST_DIRECTORY)

const customOptions = {
Expand All @@ -19,7 +19,8 @@ tap.test('json2ts runCommand', async t => {
await runCommand(inputPath, outputPath, customOptions)

const generatedFiles = fs.readdirSync(outputPath)
t.match(

t.assert.deepStrictEqual(
generatedFiles,
[
'Address.d.ts',
Expand All @@ -38,7 +39,7 @@ tap.test('json2ts runCommand', async t => {
const petFile = resolveFromPackageRoot(outputPath, 'Pet.d.ts')
const generatedPetFile = fs.readFileSync(petFile, 'utf-8')

t.same(
t.assert.deepStrictEqual(
generatedPetFile,
`import { Category } from "./Category";
import { Tag } from "./Tag";
Expand Down Expand Up @@ -69,7 +70,7 @@ export interface Pet {
const customerFile = resolveFromPackageRoot(outputPath, 'Customer.d.ts')
const generatedCustomerFile = fs.readFileSync(customerFile, 'utf-8')

t.same(
t.assert.deepStrictEqual(
generatedCustomerFile,
`import { Address } from "./Address";
Expand Down
Loading

0 comments on commit 118fd16

Please sign in to comment.