-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
456 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"displayName": "ts-express-react-starter-kit - integration", | ||
"setupFiles": [ | ||
"raf/polyfill", | ||
"core-js/modules/es7.symbol.async-iterator", | ||
"core-js/modules/es7.symbol.async-iterator" | ||
], | ||
"setupTestFrameworkScriptFile": "./src/__tests__/integrationTestSetup.ts", | ||
"transform": { | ||
"\\.(gql|graphql)$": "jest-transform-graphql", | ||
"\\.(ts|tsx)$": "ts-jest", | ||
".*": "<rootDir>/babel-jest.js" | ||
}, | ||
"watchPathIgnorePatterns": ["/lib/*", "/node_modules/*"], | ||
"moduleNameMapper": { | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html|yml)$": "<rootDir>/src/__mocks__/fileMock.js", | ||
"\\.(scss|css)$": "identity-obj-proxy", | ||
"^client/(.*)": "<rootDir>/src/client/$1", | ||
"^__tests__/(.*)": "<rootDir>/src/__tests__/$1", | ||
"^server/(.*)": "<rootDir>/src/server/$1", | ||
"^universal/(.*)": "<rootDir>/src/universal/$1" | ||
}, | ||
"testRegex": "src/?.*/__tests__/.*\\.integ\\.spec\\.(ts|tsx|js|jsx)$", | ||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"], | ||
"globals": { | ||
"__DEV__": true, | ||
"__SERVER__": false, | ||
"__PROD__": false, | ||
"__HMR__": false, | ||
"ts-jest": { | ||
"tsConfig": "./tsconfig.test.json", | ||
"diagnostics": false | ||
} | ||
}, | ||
"globalSetup": "./src/__tests__/integration-global-setup.js", | ||
"globalTeardown": "./src/__tests__/integration-global-teardown.js", | ||
"testEnvironment": "./src/__tests__/integration-environment.js", | ||
"snapshotSerializers": ["enzyme-to-json/serializer"], | ||
"testURL": "http://localhost", | ||
"preset": "ts-jest/presets/js-with-babel", | ||
"testMatch": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const range = require('lodash/range') | ||
const random = require('lodash/random') | ||
const sample = require('lodash/sample') | ||
const NodeEnvironment = require('jest-environment-node') | ||
|
||
const LOWERCASE_LETTERS = 'abcdefghijklmnopqrstuvwxyz' | ||
|
||
const choice = arrayOrString => sample([...arrayOrString]) | ||
|
||
const randomString = (charsCount, alphabet = LOWERCASE_LETTERS) => | ||
range(charsCount) | ||
.map(_ => choice(alphabet)) | ||
.join('') | ||
|
||
const id = (charsCount = 17) => randomString(charsCount, LOWERCASE_LETTERS) | ||
|
||
class IntegrationEnvironment extends NodeEnvironment { | ||
constructor(config) { | ||
super(config) | ||
} | ||
|
||
async setup() { | ||
const COLLECTION_PREFIX = `${id()}_` | ||
this.global.COLLECTION_PREFIX = COLLECTION_PREFIX | ||
this.global.PORT = random(3010, 9000) | ||
this.global.ROOT_URL = `http://localhost:${this.global.PORT}` | ||
|
||
await super.setup() | ||
} | ||
|
||
async teardown() { | ||
await super.teardown() | ||
} | ||
|
||
runScript(script) { | ||
return super.runScript(script) | ||
} | ||
} | ||
|
||
module.exports = IntegrationEnvironment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const MongodbMemoryServer = require('mongodb-memory-server') | ||
|
||
module.exports = async () => { | ||
global.__TEARDOWN__ = [] | ||
|
||
const MONGO_DB_NAME = 'jest' | ||
const mongod = new MongodbMemoryServer.default({ | ||
instance: { | ||
dbName: MONGO_DB_NAME, | ||
}, | ||
binary: { | ||
version: '4.0.4', | ||
}, | ||
}) | ||
|
||
global.__TEARDOWN__.push(async () => { | ||
console.log('Teardown mongod') | ||
await mongod.stop() | ||
}) | ||
process.env.MONGODB_URI = await mongod.getConnectionString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = async function() { | ||
await Promise.all(global.__TEARDOWN__.map(fn => fn)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {createApolloServer} from 'code/server/apollo/createApolloServer' | ||
import {runHttpServer} from 'code/server/bootstrap/runHttpServer' | ||
import {setupExternalResources} from 'code/server/bootstrap/setupExternalResources' | ||
import {runStartup, runTeardown} from 'code/server/utils/startup' | ||
|
||
/* tslint:disable:no-console */ | ||
/* globals PORT */ | ||
|
||
jest.setTimeout(10000) | ||
|
||
beforeAll(async () => { | ||
await setupExternalResources() | ||
await runStartup() | ||
await createApolloServer() | ||
await runHttpServer() | ||
}) | ||
|
||
afterAll(async () => { | ||
try { | ||
await runTeardown() | ||
} catch (err) { | ||
console.log('err', err) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/code/server/apollo/foo/model/__tests__/fooSchema.integ.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {FooModel} from 'code/server/apollo/foo/model/fooSchema' | ||
|
||
describe('fooSchema', () => { | ||
it('should create a foo', async () => { | ||
const title = 'My title' | ||
const foo = await FooModel.create({ | ||
title, | ||
}) | ||
expect(foo.title).toBe(title) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import mongoose from 'mongoose' | ||
import {prefixCollection} from 'code/server/utils/prefixCollection' | ||
import mongoose, {Document} from 'mongoose' | ||
|
||
export const fooSchema = new mongoose.Schema({ | ||
title: {type: String, required: true}, | ||
}) | ||
|
||
export const FooModel = mongoose.model('Foo', fooSchema) | ||
interface FooDocument extends Document { | ||
title: string | ||
} | ||
|
||
export const FooModel = mongoose.model<FooDocument>( | ||
prefixCollection('Foo'), | ||
fooSchema | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import mongoose from 'mongoose' | ||
|
||
export const setupExternalResources = async () => { | ||
await mongoose.connect( | ||
process.env.MONGODB_URI!, | ||
{ | ||
useNewUrlParser: true, | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* globals PORT */ | ||
|
||
export const getPort = () => | ||
typeof PORT !== 'undefined' ? PORT : process.env.PORT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* globals ROOT_URL */ | ||
|
||
export const getRootUrl = () => | ||
typeof ROOT_URL !== 'undefined' ? ROOT_URL : process.env.ROOT_URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* global COLLECTION_PREFIX */ | ||
|
||
export const getCollectionPrefix = () => { | ||
if (process.env.COLLECTION_PREFIX) { | ||
return process.env.COLLECTION_PREFIX | ||
} | ||
|
||
return typeof COLLECTION_PREFIX !== 'undefined' ? COLLECTION_PREFIX : '' | ||
} | ||
|
||
export const prefixCollection = collection => getCollectionPrefix() + collection |
Oops, something went wrong.