Skip to content

Commit

Permalink
Merge pull request #367 from guardian/aa-publish
Browse files Browse the repository at this point in the history
chore: add an integration test project
  • Loading branch information
akash1810 authored Apr 1, 2021
2 parents 944c183 + 62227da commit 4cad8aa
Show file tree
Hide file tree
Showing 22 changed files with 246 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integration-test/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
cdk.out
.eslintrc.js
jest.config.js
20 changes: 20 additions & 0 deletions integration-test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
root: true,
env: {
node: true,
jest: true,
},
extends: ["@guardian/eslint-config-typescript"],
parserOptions: {
ecmaVersion: 2020,
tsconfigRootDir: __dirname,
sourceType: "module",
project: ["./tsconfig.eslint.json"],
},
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/no-inferrable-types": 0,
"import/no-namespace": 2,
},
ignorePatterns: ["**/*.js", "node_modules"],
};
7 changes: 7 additions & 0 deletions integration-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Output directory for generated cloudformation.
cdk.out

# Ignore package-lock.json to avoid the following error when reinstalling dependencies:
# npm ERR! notarget No matching version found for [email protected].
# This is because we're installing @guardian/cdk from file, which is in turn installing eslint-plugin-custom-rules from file.
package-lock.json
1 change: 1 addition & 0 deletions integration-test/.nvmrc
3 changes: 3 additions & 0 deletions integration-test/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
11 changes: 11 additions & 0 deletions integration-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Integration Test

This is a really simple integration test for the @guardian/cdk library.

The purpose of this is to ensure:
- the library can be installed into a project
- a stack can be synthed without error

This is in reaction to [#356](https://github.com/guardian/cdk/pull/356) and [#365](https://github.com/guardian/cdk/pull/365) which broke the package.
The integration test helps increase confidence in any future changes to the library, _before_ publishing them.
That is, the feedback loop is shortened.
6 changes: 6 additions & 0 deletions integration-test/bin/cdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "source-map-support/register";
import { App } from "@aws-cdk/core";
import { IntegrationTestStack } from "../src/integration-test-stack";

const app = new App();
new IntegrationTestStack(app, "Cdk", { stack: "integration-test" });
9 changes: 9 additions & 0 deletions integration-test/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"app": "npx ts-node bin/cdk.ts",
"profile": "does-not-exist",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true"
}
}
6 changes: 6 additions & 0 deletions integration-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testMatch: ["<rootDir>/src/**/*.test.ts"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
};
41 changes: 41 additions & 0 deletions integration-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@guardian/cdk-integration-test",
"version": "1.0.0",
"description": "Integration tests for @guardian/cdk",
"bin": {
"cdk": "bin/cdk.js"
},
"scripts": {
"build": "tsc --noEmit",
"watch": "tsc -w",
"test": "jest --runInBand --detectOpenHandles",
"test:dev": "jest --runInBand --detectOpenHandles --watch",
"format": "prettier --write \"{src,bin}/**/*.ts\"",
"cdk": "cdk",
"lint": "eslint src/** bin/** --ext .ts --no-error-on-unmatched-pattern",
"generate": "cdk synth --path-metadata false --version-reporting false"
},
"devDependencies": {
"@guardian/eslint-config-typescript": "^0.5.0",
"@types/jest": "^26.0.22",
"@types/node": "14.14.37",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"aws-cdk": "1.94.1",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-custom-rules": "file:../eslint",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.4.2",
"prettier": "^2.2.1",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.1",
"typescript": "~4.2.3"
},
"dependencies": {
"@guardian/cdk": "file:.."
},
"private": true
}
6 changes: 6 additions & 0 deletions integration-test/script/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e

npm run build
npm run generate
13 changes: 13 additions & 0 deletions integration-test/script/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

# Ignore package-lock.json to avoid the following error when reinstalling dependencies:
# npm ERR! notarget No matching version found for [email protected].
# This is because we're installing @guardian/cdk from file, which is in turn installing eslint-plugin-custom-rules from file.
npm install --no-package-lock

npm run build
npm run lint
npm run test
npm run generate
5 changes: 5 additions & 0 deletions integration-test/script/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

npm run lint
8 changes: 8 additions & 0 deletions integration-test/script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

# Ignore package-lock.json to avoid the following error when reinstalling dependencies:
# npm ERR! notarget No matching version found for [email protected].
# This is because we're installing @guardian/cdk from file, which is in turn installing eslint-plugin-custom-rules from file.
npm install --no-package-lock
5 changes: 5 additions & 0 deletions integration-test/script/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

npm run test:dev
7 changes: 7 additions & 0 deletions integration-test/script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

npm run lint
npm run test
npm run generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`The Cdk stack matches the snapshot 1`] = `
Object {
"Parameters": Object {
"Stage": Object {
"AllowedValues": Array [
"CODE",
"PROD",
],
"Default": "CODE",
"Description": "Stage name",
"Type": "String",
},
},
}
`;
12 changes: 12 additions & 0 deletions integration-test/src/integration-test-stack.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "@aws-cdk/assert/jest";
import { SynthUtils } from "@aws-cdk/assert";
import { App } from "@aws-cdk/core";
import { IntegrationTestStack } from "./integration-test-stack";

describe("The Cdk stack", () => {
it("matches the snapshot", () => {
const app = new App();
const stack = new IntegrationTestStack(app, "cdk", { stack: "integration-test" });
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
});
});
9 changes: 9 additions & 0 deletions integration-test/src/integration-test-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { App } from "@aws-cdk/core";
import type { GuStackProps } from "@guardian/cdk/lib/constructs/core";
import { GuStack } from "@guardian/cdk/lib/constructs/core";

export class IntegrationTestStack extends GuStack {
constructor(scope: App, id: string, props: GuStackProps) {
super(scope, id, props);
}
}
7 changes: 7 additions & 0 deletions integration-test/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*", "bin/**/*"
],
"exclude": ["node_modules"]
}
39 changes: 39 additions & 0 deletions integration-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
},
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"lib": ["ES2020"],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"esModuleInterop": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": ["./node_modules/@types"],
"outDir": "dist"
},
"include": [
"src/**/*", "bin/**/*"
],
"exclude": [
"node_modules",
"cdk.out",
"src/**/*.test.ts",
"src/**/__snapshots__/**"
]
}
10 changes: 10 additions & 0 deletions script/ci
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
set -e

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
ROOT_DIR=$DIR/..

preamble() {
"${DIR}"/check-yarn-lock
"${DIR}"/check-aws-cdk
}

runIntegrationTest() {
(
cd "$ROOT_DIR/integration-test"
./script/ci
)
}

main() {
preamble

Expand All @@ -17,6 +25,8 @@ main() {
npm run lint
npm run test:custom-lint-rule
npm run test

runIntegrationTest
}

main

0 comments on commit 4cad8aa

Please sign in to comment.