Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI]: Add a snapshot test and modified CDK infra to run test in the CodePipeline #46

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cli/templates/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ docker-data

.nestjs_repl_history

.env
.env

report
4 changes: 4 additions & 0 deletions packages/cli/templates/infra/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
reporters: [
'default',
['jest-junit', { outputDirectory: '../report', outputName: 'unit-infra.xml' }],
],
}
11 changes: 7 additions & 4 deletions packages/cli/templates/infra/libs/build-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export function buildApp(env: Env, isLocal = false) {
}
}

const runCommand = function (cmd: string) {
const runCommand = function (cmd: string, cwdExec: string = cwd) {
console.log(cmd)
const ret = execSync(cmd, { cwd })
const ret = execSync(cmd, { cwd: cwdExec })
console.log(ret.toString())
}

Expand All @@ -48,11 +48,9 @@ export function buildApp(env: Env, isLocal = false) {
const prunePath = `${layerPath}/prune`
runCommand(`mkdir -p ${prunePath}`)
runCommand(`npm --prefix ./${prunePath} i node-prune modclean`)
runCommand(`npm --prefix ./${prunePath} exec node-prune`)
runCommand(
`npm --prefix ./${prunePath} exec modclean -- -n default:safe,default:caution -r`,
)
runCommand(`rm -rf ${prunePath}`)
runCommand(
'mv node_modules/.prisma/client/libquery_engine-linux-arm64-* prisma',
)
Expand All @@ -69,6 +67,11 @@ export function buildApp(env: Env, isLocal = false) {
runCommand(`mkdir -p ${nodejsLayerPath}`)
runCommand(`mv node_modules ${nodejsLayerPath}`)

// min size layer
console.log('============= min size layer =============')
runCommand(`npm --prefix ../prune exec node-prune`, `${layerFullPath}/nodejs`)
runCommand(`rm -rf ${prunePath}`)

console.log('============= build app finished =============')

if (isLocal) {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/templates/infra/libs/pipeline-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class PipelineStack extends Stack {

const testStep = new CodeBuildStep(`${prefix}Test`, {
projectName: `${prefix}Test`,
installCommands: ['npm ci'],
commands: ['npm run test'],
installCommands: ['npm ci', 'npm --prefix ./infra ci'],
commands: ['npm run test', 'npm --prefix ./infra run test'],
primaryOutputDirectory: 'report',
partialBuildSpec: BuildSpec.fromObject({
reports: {
[unitTestReports.reportGroupArn]: {
files: ['unit.xml'],
files: ['*.xml'],
'base-directory': 'report',
'discard-paths': true,
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/templates/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@types/node": "^20.9.4",
"aws-cdk": "^2.147.0",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand Down
Loading