Skip to content

Commit

Permalink
chore: migrate tests from js -> ts
Browse files Browse the repository at this point in the history
  • Loading branch information
etroynov committed Jun 28, 2024
1 parent c332202 commit 0176f81
Show file tree
Hide file tree
Showing 75 changed files with 691 additions and 552 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app.compose', () => {
it('should work with default compose ', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app.context', () => {
const app1 = new Koa()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app.currentContext', () => {
it('should throw error if AsyncLocalStorage not support', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app', () => {
// ignore test on Node.js v18
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'
import util from 'node:util'
import assert from 'node:assert'
import Koa from '../..'

import { describe, it } from '@jest/globals'

const assert = require('assert')
const util = require('util')
const Koa = require('../..')
const app = new Koa()

describe('app.inspect()', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
import assert from 'node:assert'
import Koa from '../..'

const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app.onerror(err)', () => {
it('should throw an error if a non-error is given', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app.request', () => {
const app1 = new Koa()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'
import statuses from 'statuses'
import request from 'supertest'
import assert from 'node:assert'
import fs from 'node:fs'
import Koa from '../..'

const request = require('supertest')
const statuses = require('statuses')
const assert = require('assert')
const Koa = require('../..')
const fs = require('fs')
import { describe, it } from '@jest/globals'

describe('app.respond', () => {
describe('when ctx.respond === false', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('app.response', () => {
const app1 = new Koa()
Expand Down
6 changes: 3 additions & 3 deletions __tests__/context/assert.js → __tests__/context/assert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
import assert from 'node:assert'
import context from '../../test-helpers/context'

const context = require('../../test-helpers/context')
const assert = require('assert')
import { describe, it } from '@jest/globals'

describe('ctx.assert(value, status)', () => {
it('should throw an error', () => {
Expand Down
8 changes: 4 additions & 4 deletions __tests__/context/cookies.js → __tests__/context/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const assert = require('assert')
const request = require('supertest')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('ctx.cookies', () => {
describe('ctx.cookies.set()', () => {
Expand Down
22 changes: 0 additions & 22 deletions __tests__/context/inspect.js

This file was deleted.

22 changes: 22 additions & 0 deletions __tests__/context/inspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import assert from 'node:assert'
import util from 'node:util'
import createContext from '../../test-helpers/context'
import context from '../../lib/context'

import { describe, it } from '@jest/globals'

describe('ctx.inspect()', () => {
it('should return a json representation', () => {
const ctx = createContext()
const toJSON = ctx.toJSON(ctx)

assert.deepStrictEqual(toJSON, ctx.inspect())
assert.deepStrictEqual(util.inspect(toJSON), util.inspect(ctx))
})

// console.log(require.cache) will call context.inspect()
it('should not crash when called on the prototype', () => {
assert.deepStrictEqual(context, context.inspect())
assert.deepStrictEqual(util.inspect(context.inspect()), util.inspect(context))
})
})
12 changes: 6 additions & 6 deletions __tests__/context/onerror.js → __tests__/context/onerror.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import createContext from '../../test-helpers/context'
import Koa from '../..'

const assert = require('assert')
const request = require('supertest')
const Koa = require('../..')
const context = require('../../test-helpers/context')
import { describe, it } from '@jest/globals'

describe('ctx.onerror(err)', () => {
it('should respond', () => {
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('ctx.onerror(err)', () => {

it('should use res.getHeaderNames() accessor when available', () => {
let removed = 0
const ctx = context()
const ctx = createContext()

ctx.app.emit = () => {}
ctx.res = {
Expand Down
8 changes: 4 additions & 4 deletions __tests__/context/state.js → __tests__/context/state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
import request from 'supertest'
import assert from 'node:assert'
import Koa from '../..'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')
import { describe, it } from '@jest/globals'

describe('ctx.state', () => {
it('should provide a ctx.state namespace', () => {
Expand Down
32 changes: 16 additions & 16 deletions __tests__/context/throw.js → __tests__/context/throw.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'
import assert from 'node:assert'
import createContext from '../../test-helpers/context'

const context = require('../../test-helpers/context')
const assert = require('assert')
import { describe, it } from '@jest/globals'

describe('ctx.throw(msg)', () => {
it('should set .status to 500', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw('boom')
Expand All @@ -18,7 +18,7 @@ describe('ctx.throw(msg)', () => {

describe('ctx.throw(err)', () => {
it('should set .status to 500', () => {
const ctx = context()
const ctx = createContext()
const err = new Error('test')

try {
Expand All @@ -33,7 +33,7 @@ describe('ctx.throw(err)', () => {

describe('ctx.throw(err, status)', () => {
it('should throw the error and set .status', () => {
const ctx = context()
const ctx = createContext()
const error = new Error('test')

try {
Expand All @@ -48,7 +48,7 @@ describe('ctx.throw(err, status)', () => {

describe('ctx.throw(status, err)', () => {
it('should throw the error and set .status', () => {
const ctx = context()
const ctx = createContext()
const error = new Error('test')

try {
Expand All @@ -63,7 +63,7 @@ describe('ctx.throw(status, err)', () => {

describe('ctx.throw(msg, status)', () => {
it('should throw an error', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw('name required', 400)
Expand All @@ -77,7 +77,7 @@ describe('ctx.throw(msg, status)', () => {

describe('ctx.throw(status, msg)', () => {
it('should throw an error', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw(400, 'name required')
Expand All @@ -91,7 +91,7 @@ describe('ctx.throw(status, msg)', () => {

describe('ctx.throw(status)', () => {
it('should throw an error', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw(400)
Expand All @@ -104,7 +104,7 @@ describe('ctx.throw(status)', () => {

describe('when not valid status', () => {
it('should not expose', () => {
const ctx = context()
const ctx = createContext()

try {
const err = new Error('some error')
Expand All @@ -120,7 +120,7 @@ describe('ctx.throw(status)', () => {

describe('ctx.throw(status, msg, props)', () => {
it('should mixin props', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw(400, 'msg', { prop: true })
Expand All @@ -134,7 +134,7 @@ describe('ctx.throw(status, msg, props)', () => {

describe('when props include status', () => {
it('should be ignored', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw(400, 'msg', {
Expand All @@ -153,7 +153,7 @@ describe('ctx.throw(status, msg, props)', () => {

describe('ctx.throw(msg, props)', () => {
it('should mixin props', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw('msg', { prop: true })
Expand All @@ -168,7 +168,7 @@ describe('ctx.throw(msg, props)', () => {

describe('ctx.throw(status, props)', () => {
it('should mixin props', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw(400, { prop: true })
Expand All @@ -183,7 +183,7 @@ describe('ctx.throw(status, props)', () => {

describe('ctx.throw(err, props)', () => {
it('should mixin props', () => {
const ctx = context()
const ctx = createContext()

try {
ctx.throw(new Error('test'), { prop: true })
Expand Down
8 changes: 4 additions & 4 deletions __tests__/context/toJSON.js → __tests__/context/toJSON.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'
import assert from 'node:assert'
import createContext from '../../test-helpers/context'

const assert = require('assert')
const context = require('../../test-helpers/context')
import { describe, it } from '@jest/globals'

describe('ctx.toJSON()', () => {
it('should return a json representation', () => {
const ctx = context()
const ctx = createContext()

ctx.req.method = 'POST'
ctx.req.url = '/items'
Expand Down
Loading

0 comments on commit 0176f81

Please sign in to comment.