lite-unit-test
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

lite-unit-test

Its a wrapper tool to build unit test in node with the native assert library

// ...users/test.ts
import assert from 'node:assert'
import { LightTestModule } from 'lite-unit-test'

const unit: LightTestModule = {}

unit['2 equals 2'] = (done) => {
  assert.strictEqual(2, 2)
  done()
}

export default unit
// ...allData/test.ts
import assert from 'node:assert'
import { LightTestModule } from 'lite-unit-test'
import { getAll } from './db'
import { CompanyFullDataSchema } from './schema'
import { ZodError } from 'zod'

const unit: LightTestModule = {}

unit['getAll does not throw'] = (done) => {
  assert.doesNotThrow(getAll)
  done()
}

unit['Database has more than 7k records'] = async (done) => {
  const res = await getAll()
  assert.strictEqual(res.length > 7000, true)
  done()
}

unit['Zod Schema validates ALL THE DATA'] = async (done) => {
  try {
    const data = await getAll()
    data.forEach((e) => CompanyFullDataSchema.parse(e))
  } catch (error) {
    if (error instanceof ZodError) {
      throw new assert.AssertionError({
        message: 'Zod Validation Failed'
      })
    }
    throw error
  }
  done()
}
import lightTest from 'lite-unit-test'
import allData from './component/allData/test'
import users from './component/users/test'

lightTest.addTestModule('allData', allData)
lightTest.addTestModule('users', users)

lightTest.runTests()
"scripts": {
  ...,
  "unit-test": "ts-node src/unit-tests.ts"
}
npm run unit-test

> trpc@1.0.0 unit-test
> ts-node src/unit-tests.ts

getAll does not throw
2 equals 2
Zod Schema fails ALL THE DATA
Database has more than 7k records
Zod Schema validates ALL THE DATA
---------------------------------------------------------------------------------------------
                                       BEGIN TEST REPORT
---------------------------------------------------------------------------------------------
Total tests                                                       5
Pass                                                              5
Fail                                                              0
---------------------------------------------------------------------------------------------
                                         END OF TESTS
---------------------------------------------------------------------------------------------

Package Sidebar

Install

npm i lite-unit-test

Weekly Downloads

0

Version

1.2.3

License

ISC

Unpacked Size

18.2 kB

Total Files

7

Last publish

Collaborators

  • zitrojj