Skip to content

Instantly share code, notes, and snippets.

🙂
Coding

Grant Carthew grantcarthew

🙂
Coding
  • Brisbane, Australia
Block or report user

Report or block grantcarthew

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Invoke-GitHubPing.ps1
$logPath = 'D:\Temp\github-ping.log'
$title = "Script started at " + (Get-Date)
Set-Content -Value $title -Path $logPath
Write-Host -Object $title
$ip = 'Error'
$logIt = $false
$count = 0
$result = $null
$newResult = $null
$newIp = $null
@grantcarthew
grantcarthew / global-teardown.js
Created Mar 2, 2019
medium-global-teardown.js
View global-teardown.js
// global-teardown.js
module.exports = async function () {
await global.__MONGOD__.stop()
}
@grantcarthew
grantcarthew / http-setup.js
Created Mar 2, 2019
medium-http-setup.js
View http-setup.js
// http-setup.js
const axios = require('axios')
const app = require('../../src/server')
const log = require('../../src/logger').child(module)
module.exports = async function httpSetup () {
log.info('HTTP test setup initiated')
const listener = app.listen()
const port = listener.address().port
const baseURL = `http://localhost:${port}/api`
View medium-product.test.js
// product.test.js
const axios = require('axios')
const driver = require('../src/store/driver')
const httpSetup = require('./setup/http-setup')
const log = require('../src/logger')
let listener
beforeAll(async function () {
await driver.connect(global.__MONGO_URI__)
@grantcarthew
grantcarthew / mongo-environment.js
Created Mar 2, 2019
medium-mongo-environment.js
View mongo-environment.js
// mongo-environment.js
const NodeEnvironment = require('jest-environment-node')
const path = require('path')
const fs = require('fs')
const globalConfigPath = path.join(__dirname, 'globalConfig.json')
const log = require('../../src/logger')
class MongoEnvironment extends NodeEnvironment {
constructor (config) {
super(config)
View db-setup.js
// db-setup.js
const path = require('path')
const fs = require('fs')
const { MongoMemoryServer } = require('mongodb-memory-server')
const driver = require('../../src/store/driver')
const initializeDb = require('../initialize-db')
const globalConfigPath = path.join(__dirname, 'globalConfig.json')
const mongod = new MongoMemoryServer({
@grantcarthew
grantcarthew / global-setup.js
Created Mar 2, 2019
medium-global-setup.js
View global-setup.js
// global-setup.js
const dbSetup = require('./db-setup')
module.exports = async function () {
await dbSetup()
}
@grantcarthew
grantcarthew / jest.config.js
Last active Mar 1, 2019
medium-jest.config.js
View jest.config.js
// jest.config.js
module.exports = {
clearMocks: true,
globalSetup: '<rootDir>/tests/setup/global-setup.js',
globalTeardown: '<rootDir>/tests/setup/global-teardown.js',
testEnvironment: '<rootDir>/tests/setup/mongo-environment.js'
}
@grantcarthew
grantcarthew / package.json
Last active Mar 1, 2019
medium-package.json
View package.json
// package.json <= JSON does not support comments. Remove this line.
{
"name": "example",
"version": "1.0.0",
"description": "Example for test script",
"main": "index.js",
"scripts": {
"test": "LOGENABLED=true LOGLEVEL=error DBCONNECTIONPOOLMAX=10 DBCONNECTIONPOOLIDLE=50 jest --watch"
},
"author": "",
@grantcarthew
grantcarthew / app.js
Last active Mar 1, 2019
medium-app.js
View app.js
//app.js
// Constants
const MAX_CONTENT_LENGTH_ACCEPTED = 102400000
const COOKIESIGNSECRET = process.env.COOKIESIGNSECRET
// Core Modules
const express = require('express')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
You can’t perform that action at this time.