Skip to content

Commit e8187b3

Browse files
authoredFeb 5, 2019
Init testing (DataDog#3)
* init karma mocha * plug webpack + typescript * wire to CI * replace .npmrc by .yarnrc
1 parent 77c2b5c commit e8187b3

9 files changed

+1647
-41
lines changed
 

‎.gitlab-ci.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variables:
22
APP: "browser-agent"
3-
CURRENT_CI_IMAGE: 2
3+
CURRENT_CI_IMAGE: 3
44
BUILD_STABLE_REGISTRY: "486234852809.dkr.ecr.us-east-1.amazonaws.com"
55
CI_IMAGE: "$BUILD_STABLE_REGISTRY/ci/$APP:$CURRENT_CI_IMAGE"
66

@@ -41,3 +41,11 @@ build:
4141
script:
4242
- yarn
4343
- yarn build
44+
45+
test:
46+
stage: test
47+
tags: ["runner:main", "size:large"]
48+
image: $CI_IMAGE
49+
script:
50+
- yarn
51+
- yarn test

‎.yarnrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
save-exact true
2+

‎Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
11
FROM node:11.6.0-slim
2+
3+
# Install Chrome deps.
4+
RUN apt-get update && apt-get install -y -q --no-install-recommends \
5+
libgtk-3-dev \
6+
libx11-xcb1 \
7+
libnss3 \
8+
libxss1 \
9+
libasound2 \
10+
fonts-liberation \
11+
libappindicator3-1 \
12+
lsb-release \
13+
xdg-utils
14+
15+
# Download and install Chrome.
16+
# Debian taken from https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable
17+
RUN curl --silent --show-error --fail https://dd-public-oss-mirror.s3.amazonaws.com/google-chrome-stable_71.0.3578.80-1_amd64.deb --output google-chrome.deb \
18+
&& dpkg -i google-chrome.deb \
19+
&& rm google-chrome.deb

‎karma.conf.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const webpackConfig = require("./webpack.config")(null, "development");
2+
3+
module.exports = function(config) {
4+
config.set({
5+
browsers: ["ChromeHeadlessNoSandbox"],
6+
customLaunchers: {
7+
ChromeHeadlessNoSandbox: {
8+
base: "ChromeHeadless",
9+
flags: ["--no-sandbox"]
10+
}
11+
},
12+
files: ["**/*.unit.ts"],
13+
frameworks: ["mocha", "chai"],
14+
preprocessors: {
15+
"src/**/*.unit.ts": ["webpack"]
16+
},
17+
singleRun: true,
18+
webpack: {
19+
mode: "development",
20+
stats: "minimal",
21+
module: webpackConfig.module,
22+
resolve: webpackConfig.resolve
23+
},
24+
webpackMiddleware: {
25+
stats: "errors-only",
26+
logLevel: "warn"
27+
}
28+
});
29+
};

‎package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@
66
"build": "webpack --config webpack.config.js --mode=production",
77
"dev": "webpack-dev-server --mode=development",
88
"format": "prettier --check \"**/*.{ts,js,json,md,yml}\" \"!dist/**\"",
9-
"lint": "tslint -c ./tslint.json -p ./tsconfig.json"
9+
"lint": "tslint -c ./tslint.json -p ./tsconfig.json",
10+
"test": "karma start"
1011
},
1112
"devDependencies": {
13+
"@types/chai": "4.1.7",
14+
"@types/mocha": "5.2.5",
15+
"chai": "4.2.0",
16+
"karma": "4.0.0",
17+
"karma-chai": "0.1.0",
18+
"karma-chrome-launcher": "2.2.0",
19+
"karma-mocha": "1.3.0",
20+
"karma-typescript-preprocessor2": "1.2.1",
21+
"karma-webpack": "3.0.5",
22+
"mocha": "5.2.0",
1223
"prettier": "1.16.2",
1324
"ts-loader": "5.3.3",
1425
"tslint": "5.12.1",

‎src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
console.log("Hello");
1+
export function add(a: number, b: number) {
2+
return a + b;
3+
}

‎src/index.unit.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { expect } from "chai";
2+
import { add } from "./index";
3+
4+
describe("test", () => {
5+
it("should pass", () => {
6+
expect(add(1, 2)).to.equal(3);
7+
});
8+
});

‎tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"member-access": false,
1616
"no-console": false,
1717
"no-default-export": true,
18+
"no-implicit-dependencies": [true, "dev"],
1819
"ter-computed-property-spacing": false
1920
},
2021
"rulesDirectory": []

‎yarn.lock

+1,565-38
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.