Skip to content

Commit

Permalink
ci: move e2e script to dedicated directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandotv committed Jul 14, 2022
1 parent f5c2c69 commit 5831294
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "next start",
"test:db": "jest --selectProjects database",
"test:api": "jest --selectProjects api",
"test:e2e": "node ./scripts/test-e2e.mjs",
"test:e2e": "node ./scripts-ci/test-e2e.mjs",
"cy:open": "cypress open --browser chrome",
"cy:run": "cypress run --browser chrome",
"analyze": "ANALYZE=true && pnpm run build",
Expand Down
85 changes: 85 additions & 0 deletions scripts-ci/test-e2e.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as dotenv from 'dotenv'
import { type } from 'node:os'
import path, { dirname } from 'node:path'
import { GenericContainer } from 'testcontainers'
import { fileURLToPath } from 'url'
import { $ } from 'zx'
import 'zx/globals'

const __dirname = dirname(fileURLToPath(import.meta.url))

;(async function main() {
//disable automatic cleanup of test containers
process.env.TESTCONTAINERS_RYUK_DISABLED = true

let mongoContainer
let server
let hasError = false
try {
dotenv.config({
debug: true,
override: true,
path: path.resolve(__dirname, '../', '.env.test')
})

mongoContainer = await startMongo()

process.env.NODE_ENV = 'test'
process.env.E2E = 'true'

server = $`pnpm start`

await $`pnpm cypress run --browser chrome`
} catch (e) {
hasError = true
console.log(e)
} finally {
if (mongoContainer) {
console.log('stopping mongo')
await mongoContainer.stop()
console.log('mongo stopped')
}
if (server) {
console.log('stopping server')
await server.kill()
console.log('server stopped')
}

process.exit(hasError ? 1 : 0)
}
})()

async function startMongo() {
const remoteContainers =
Boolean(process.env.REMOTE_CONTAINERS) || Boolean(process.env.CODESPACES)
const newtworkAlias = 'mongo-test-db'

const mongoContainer = new GenericContainer('mongo:5.0.8').withExposedPorts(
27017
)

console.log('using remote containers: ', remoteContainers)

if (type() === 'Linux') {
console.log('mongo: using tmpfs mount')
mongoContainer.withTmpFs({ '/data/db': '' })
}
if (remoteContainers) {
mongoContainer
.withNetworkMode('development')
.withNetworkAliases(newtworkAlias)
}

const mongoStarted = await mongoContainer.start()

const host = remoteContainers ? newtworkAlias : 'localhost'

const port = remoteContainers ? '27017' : mongoStarted.getMappedPort(27017)

process.env.MONGO_DB_URI = `mongodb://${host}:${port}`

console.log('mongo db started')
console.log('MONGO_DB_URI: ', process.env.MONGO_DB_URI)

return mongoStarted
}

1 comment on commit 5831294

@vercel
Copy link

@vercel vercel bot commented on 5831294 Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-radio – ./

next-radio-ivandotv.vercel.app
live-radio.vercel.app
next-radio-git-master-ivandotv.vercel.app

Please sign in to comment.