Skip to content

Commit

Permalink
Merge pull request #46 from mbc-net/test/infra
Browse files Browse the repository at this point in the history
[CLI]:  Add a snapshot test and modified CDK infra to run test in the CodePipeline
  • Loading branch information
koichimurakami authored Nov 14, 2024
2 parents 7c50d38 + ae00598 commit bb94df5
Show file tree
Hide file tree
Showing 7 changed files with 2,491 additions and 8 deletions.
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

0 comments on commit bb94df5

Please sign in to comment.