Skip to content

Commit 606e011

Browse files
committed
chore: adding appveyer config and integration test
1 parent 38fec78 commit 606e011

File tree

7 files changed

+3731
-65
lines changed

7 files changed

+3731
-65
lines changed

.appveyor.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
image:
2+
- Ubuntu
3+
- Visual Studio 2015
4+
5+
environment:
6+
matrix:
7+
- nodejs_version: '8'
8+
- nodejs_version: '10'
9+
10+
# Fail on first error
11+
matrix:
12+
fast_finish: true
13+
14+
# Specify cache for yarn in cross platform way
15+
for:
16+
- matrix:
17+
except:
18+
- image: Ubuntu
19+
cache:
20+
- "%LOCALAPPDATA%\\Yarn"
21+
- matrix:
22+
only:
23+
- image: Ubuntu
24+
cache:
25+
- '$HOME/.cache/yarn'
26+
27+
shallow_clone: true
28+
29+
install:
30+
# Install specified version of Node.JS (cross platform capable way)
31+
- cmd: powershell Install-Product node $env:nodejs_version
32+
- sh: nvm install $nodejs_version
33+
34+
# Set execution flag on script that runs inside docker
35+
- sh: chmod +x ./scripts/build-prod.sh
36+
37+
# install dependencies
38+
- yarn install --ignore-optional
39+
- yarn build
40+
41+
# Post-install test scripts.
42+
test_script:
43+
# Output useful info for debugging.
44+
- yarn --version
45+
- node --version
46+
- npm --version
47+
# Run all tests
48+
- yarn test
49+
50+
# Don't actually build.
51+
build: off

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
index.js

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,30 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "npx tsc index.ts",
8-
"test": "echo \"Error: no test specified\" && exit 1"
8+
"test": "node ./scripts/test-integration.js"
99
},
1010
"author": "Jason Shin",
1111
"license": "MIT",
1212
"dependencies": {
1313
"@tensorflow/tfjs-node": "0.2.1"
1414
},
1515
"devDependencies": {
16+
"@types/jest": "^23.3.11",
17+
"jest": "^23.6.0",
18+
"ts-jest": "^23.10.5",
1619
"typescript": "^3.2.2"
20+
},
21+
"jest": {
22+
"moduleFileExtensions": [
23+
"ts",
24+
"tsx",
25+
"js"
26+
],
27+
"transform": {
28+
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
29+
},
30+
"testRegex": "/test/.*\\.test.(ts|tsx|js)$",
31+
"verbose": true,
32+
"testEnvironment": "node"
1733
}
1834
}

scripts/build-prod.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Building bundles for the production purpose'
4+
5+
# Standard build
6+
echo '1. building a prod bundle'
7+
yarn build
8+
9+
# Copying all files in build/main/lib to the root folder
10+
# This is to enable the correct module export; reference: https://github.com/Microsoft/TypeScript/issues/8305
11+
# echo '2. copying the prod bundle to the root scope'
12+
# cp -a ./build/main/lib/. ./
13+
14+
# Creating a global symlink of kalimdor
15+
echo '3. creating a global link'
16+
yarn link
17+
18+
# Linking the global kalimdor to local
19+
echo '4. linking kalimdor to local'
20+
yarn link machinelearn-node
21+
22+
# Running integration test as part of the build
23+
echo '5. run the jest require tests'
24+
npx jest -t "integration:require"
25+
echo 'finished building for prod'

scripts/test-integration.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const cp = require('child_process');
2+
3+
function isDockerInstalled() {
4+
let result = true;
5+
try {
6+
cp.execSync('docker version');
7+
} catch (err) {
8+
result = false;
9+
}
10+
return result;
11+
}
12+
13+
function runIntegrationTests() {
14+
if (isDockerInstalled()) {
15+
const cmds = [
16+
{
17+
comment: '### 1. building a kalimdor docker image',
18+
cmd: 'docker build -t kalimdor:latest .'
19+
},
20+
{
21+
comment: '### 2. Running build-prod.sh in a temporary container',
22+
cmd: "docker run --rm kalimdor:latest './scripts/build-prod.sh'"
23+
}
24+
];
25+
26+
for (let i = 0; i < cmds.length; i++) {
27+
console.log(cmds[i].comment);
28+
cp.execSync(cmds[i].cmd, { stdio: [0, 1, 2] });
29+
}
30+
} else {
31+
console.warn(
32+
'Docker does not seem to be properly installed. Skipping integration tests.'
33+
);
34+
}
35+
}
36+
37+
try {
38+
runIntegrationTests();
39+
console.log('PASS Integration tests');
40+
} catch (err) {
41+
console.error('FAILED Integration tests');
42+
process.exitCode = 1;
43+
}

test/require.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('integration:require', () => {
2+
it('should require machinelearn-node', () => {
3+
require('machinelearn-node');
4+
});
5+
});

0 commit comments

Comments
 (0)