Skip to content

Commit

Permalink
Use built-in Jest types
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Oct 26, 2022
1 parent 7c6fe16 commit abc27e1
Show file tree
Hide file tree
Showing 26 changed files with 68 additions and 93 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@
{ "allow": ["fp-ts/*", "fp-ts-contrib/*", "io-ts/*", "hyper-ts/lib/*", "nanohtml/*"] }
],
"quotes": ["error", "single", { "avoidEscape": true }]
},
"settings": {
"import/core-modules": ["@jest/globals"]
}
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
isolatedModules: true,
},
},
injectGlobals: false,
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['./src/', './test/'],
Expand Down
21 changes: 0 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@types/express": "^4.17.14",
"@types/html-escaper": "^3.0.0",
"@types/http-errors": "^1.8.2",
"@types/jest": "^28.1.7",
"@types/make-fetch-happen": "^10.0.0",
"@types/markdown-it": "^12.2.3",
"@types/node": "^16.11.68",
Expand Down
1 change: 1 addition & 0 deletions test/home.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect } from '@jest/globals'
import * as E from 'fp-ts/Either'
import { MediaType, Status } from 'hyper-ts'
import * as _ from '../src/home'
Expand Down
1 change: 1 addition & 0 deletions test/html.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import * as _ from '../src/html'

describe('html', () => {
Expand Down
1 change: 1 addition & 0 deletions test/infrastructure.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, jest } from '@jest/globals'
import { Temporal } from '@js-temporal/polyfill'
import { Doi } from 'doi-ts'
import fetchMock from 'fetch-mock'
Expand Down
1 change: 1 addition & 0 deletions test/legacy-prereview.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect } from '@jest/globals'
import fetchMock from 'fetch-mock'
import * as E from 'fp-ts/Either'
import { Status } from 'hyper-ts'
Expand Down
1 change: 1 addition & 0 deletions test/log-in.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect } from '@jest/globals'
import fetchMock from 'fetch-mock'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
Expand Down
1 change: 1 addition & 0 deletions test/middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect } from '@jest/globals'
import * as E from 'fp-ts/Either'
import { MediaType, Status } from 'hyper-ts'
import * as _ from '../src/middleware'
Expand Down
8 changes: 4 additions & 4 deletions test/preprint.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, jest } from '@jest/globals'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import * as _ from '../src/preprint'
import * as fc from './fc'
import { runMiddleware } from './middleware'
Expand Down Expand Up @@ -29,10 +31,8 @@ describe('preprint', () => {
),
],
async (connection, preprint, prereviews) => {
const getPreprint: jest.MockedFunction<_.GetPreprintEnv['getPreprint']> = jest.fn(_ => TE.right(preprint))
const getPrereviews: jest.MockedFunction<_.GetPrereviewsEnv['getPrereviews']> = jest.fn(_ =>
TE.right(prereviews),
)
const getPreprint: Mock<_.GetPreprintEnv['getPreprint']> = jest.fn(_ => TE.right(preprint))
const getPrereviews: Mock<_.GetPrereviewsEnv['getPrereviews']> = jest.fn(_ => TE.right(prereviews))

const actual = await runMiddleware(_.preprint(preprint.id.doi)({ getPreprint, getPrereviews }), connection)()

Expand Down
4 changes: 3 additions & 1 deletion test/review.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, jest } from '@jest/globals'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import * as _ from '../src/review'
import * as fc from './fc'
import { runMiddleware } from './middleware'
Expand All @@ -25,7 +27,7 @@ describe('review', () => {
}),
],
async (id, connection, prereview) => {
const getPrereview: jest.MockedFunction<_.GetPrereviewEnv['getPrereview']> = jest.fn(_ => TE.right(prereview))
const getPrereview: Mock<_.GetPrereviewEnv['getPrereview']> = jest.fn(_ => TE.right(prereview))

const actual = await runMiddleware(_.review(id)({ getPrereview }), connection)()

Expand Down
1 change: 1 addition & 0 deletions test/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import * as D from 'io-ts/Decoder'
import * as _ from '../src/string'
import * as fc from './fc'
Expand Down
1 change: 1 addition & 0 deletions test/time.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect } from '@jest/globals'
import * as _ from '../src/time'
import * as fc from './fc'

Expand Down
1 change: 1 addition & 0 deletions test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'
Expand Down
8 changes: 4 additions & 4 deletions test/write-review/write-review-add-author.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { CanAddAuthorsEnv } from '../../src/feature-flags'
import { UserC } from '../../src/user'
Expand Down Expand Up @@ -54,10 +56,8 @@ describe('writeReviewAddAuthor', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const canAddAuthors: jest.MockedFunction<CanAddAuthorsEnv['canAddAuthors']> = jest.fn(_ => true)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const canAddAuthors: Mock<CanAddAuthorsEnv['canAddAuthors']> = jest.fn(_ => true)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthor(preprintDoi)({
canAddAuthors,
Expand Down
26 changes: 8 additions & 18 deletions test/write-review/write-review-add-authors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { UserC } from '../../src/user'
import * as _ from '../../src/write-review'
Expand Down Expand Up @@ -47,9 +49,7 @@ describe('writeReviewAddAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthors(preprintDoi)({
canAddAuthors: () => true,
Expand Down Expand Up @@ -112,9 +112,7 @@ describe('writeReviewAddAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthors(preprintDoi)({
canAddAuthors: () => true,
Expand Down Expand Up @@ -182,9 +180,7 @@ describe('writeReviewAddAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthors(preprintDoi)({
canAddAuthors: () => true,
Expand Down Expand Up @@ -248,9 +244,7 @@ describe('writeReviewAddAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthors(preprintDoi)({
canAddAuthors: () => true,
Expand Down Expand Up @@ -326,9 +320,7 @@ describe('writeReviewAddAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthors(preprintDoi)({
canAddAuthors: () => false,
Expand Down Expand Up @@ -395,9 +387,7 @@ describe('writeReviewAddAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAddAuthors(preprintDoi)({
canAddAuthors: () => false,
Expand Down
14 changes: 5 additions & 9 deletions test/write-review/write-review-authors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { UserC } from '../../src/user'
import * as _ from '../../src/write-review'
Expand Down Expand Up @@ -46,9 +48,7 @@ describe('writeReviewAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAuthors(preprintDoi)({
canAddAuthors: () => canAddAuthors,
Expand Down Expand Up @@ -123,9 +123,7 @@ describe('writeReviewAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAuthors(preprintDoi)({
canAddAuthors: () => canAddAuthors,
Expand Down Expand Up @@ -208,9 +206,7 @@ describe('writeReviewAuthors', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewAuthors(preprintDoi)({
canAddAuthors: () => canAddAuthors,
Expand Down
8 changes: 4 additions & 4 deletions test/write-review/write-review-change-author.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { CanAddAuthorsEnv } from '../../src/feature-flags'
import { UserC } from '../../src/user'
Expand Down Expand Up @@ -58,10 +60,8 @@ describe('writeReviewChangeAuthor', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const canAddAuthors: jest.MockedFunction<CanAddAuthorsEnv['canAddAuthors']> = jest.fn(_ => true)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const canAddAuthors: Mock<CanAddAuthorsEnv['canAddAuthors']> = jest.fn(_ => true)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewChangeAuthor(
preprintDoi,
Expand Down
6 changes: 3 additions & 3 deletions test/write-review/write-review-competing-interests.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { UserC } from '../../src/user'
import * as _ from '../../src/write-review'
Expand Down Expand Up @@ -56,9 +58,7 @@ describe('writeReviewCompetingInterests', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))

const actual = await runMiddleware(
_.writeReviewCompetingInterests(preprintDoi)({ formStore, getPreprintTitle, secret, sessionStore }),
Expand Down
6 changes: 3 additions & 3 deletions test/write-review/write-review-conduct.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { UserC } from '../../src/user'
import * as _ from '../../src/write-review'
Expand Down Expand Up @@ -55,9 +57,7 @@ describe('writeReviewConduct', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))

const actual = await runMiddleware(
_.writeReviewConduct(preprintDoi)({ formStore, getPreprintTitle, secret, sessionStore }),
Expand Down
6 changes: 3 additions & 3 deletions test/write-review/write-review-persona.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect, jest } from '@jest/globals'
import cookieSignature from 'cookie-signature'
import * as E from 'fp-ts/Either'
import * as TE from 'fp-ts/TaskEither'
import { MediaType, Status } from 'hyper-ts'
import type { Mock } from 'jest-mock'
import Keyv from 'keyv'
import { UserC } from '../../src/user'
import * as _ from '../../src/write-review'
Expand Down Expand Up @@ -56,9 +58,7 @@ describe('writeReviewPersona', () => {
await sessionStore.set(sessionId, UserC.encode(user))
const formStore = new Keyv()
await formStore.set(`${user.orcid}_${preprintDoi}`, newReview)
const getPreprintTitle: jest.MockedFunction<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ =>
TE.right(preprintTitle),
)
const getPreprintTitle: Mock<_.GetPreprintTitleEnv['getPreprintTitle']> = jest.fn(_ => TE.right(preprintTitle))
const actual = await runMiddleware(
_.writeReviewPersona(preprintDoi)({ formStore, getPreprintTitle, secret, sessionStore }),
connection,
Expand Down

0 comments on commit abc27e1

Please sign in to comment.