From c5934e338c98f20986d943d192bee82ffdf49db4 Mon Sep 17 00:00:00 2001 From: Amila Welihinda Date: Fri, 18 Jan 2019 15:23:36 -0800 Subject: [PATCH] run cli, static, and dynamic tests on CI, add tests for cache busting --- .editorconfig | 18 +++++++++ .travis.yml | 11 +++++- test/cli/package-lock.json | 6 +-- test/cli/package.json | 4 +- test/cli/src/unit/cache.ts | 77 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 .editorconfig create mode 100644 test/cli/src/unit/cache.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f6715f3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.rs] +indent_size = 4 + +[*.toml] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false diff --git a/.travis.yml b/.travis.yml index cc49825..4301724 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,9 @@ before_install: - nvm use ${TRAVIS_NODE_VERSION} - node -v - npm -v + - npm install --prefix cli + - npm install --prefix test/cli + - npm install --prefix test/dynamic addons: apt: @@ -39,8 +42,12 @@ addons: packages: - g++-4.8 -script: | - cargo test --release -- --nocapture +script: + - cargo test --release -- --nocapture + - npm test --prefix cli + - npm test --prefix test/cli + - npm test --prefix test/dynamic + - cargo test --manifest-path=test/static/Cargo.toml jobs: include: diff --git a/test/cli/package-lock.json b/test/cli/package-lock.json index 2afc70d..a05a8b9 100644 --- a/test/cli/package-lock.json +++ b/test/cli/package-lock.json @@ -77,9 +77,9 @@ "dev": true }, "@types/node": { - "version": "8.10.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.18.tgz", - "integrity": "sha512-WoepSz+wJlU5Bjq5oK6cO1oXe2FgPcjMtQPgKPS8fVaTAD0lxkScMCCbMimdkVCsykqaA4lvHWz3cmj28yimhA==", + "version": "8.10.39", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.39.tgz", + "integrity": "sha512-rE7fktr02J8ybFf6eysife+WF+L4sAHWzw09DgdCebEu+qDwMvv4zl6Bc+825ttGZP73kCKxa3dhJOoGJ8+5mA==", "dev": true }, "@types/rimraf": { diff --git a/test/cli/package.json b/test/cli/package.json index 82320cf..a6b1b6c 100644 --- a/test/cli/package.json +++ b/test/cli/package.json @@ -34,7 +34,7 @@ "@types/inquirer": "0.0.35", "@types/mkdirp": "^0.5.1", "@types/mocha": "^5.2.0", - "@types/node": "^8.0.28", + "@types/node": "^8.10.39", "@types/rimraf": "^2.0.2", "@types/rsvp": "^3.3.1", "@types/semver": "^5.3.31", @@ -49,7 +49,7 @@ "typescript": "^2.2.2" }, "scripts": { - "test": "mocha lib/acceptance", + "test": "npm run transpile && mocha lib/**/*.js", "transpile": "tsc" } } diff --git a/test/cli/src/unit/cache.ts b/test/cli/src/unit/cache.ts new file mode 100644 index 0000000..24b772b --- /dev/null +++ b/test/cli/src/unit/cache.ts @@ -0,0 +1,77 @@ +import { expect } from 'chai'; +import BuildSettings from '../../../../cli/lib/build-settings'; + +describe('build settings', () => { + const env = { + npm_config_target: null, + npm_config_arch: null, + npm_config_target_arch: null, + npm_config_disturl: null, + npm_config_runtime: null, + npm_config_build_from_source: null, + npm_config_devdir: null + }; + + describe('match', () => { + it('should not match build settings if nodeVersion is different', () => { + const buildSettings = new BuildSettings('rustc-version', 'v11.8.0', env); + const otherSettings = new BuildSettings('rustc-version', 'v10.8.0', env); + expect(buildSettings.match(otherSettings)).equal(false); + }); + + it('should match build settings if nodeVersion is same', () => { + const buildSettings = new BuildSettings('rustc-version', 'v11.8.0', env); + const otherSettings = new BuildSettings('rustc-version', 'v11.8.0', env); + expect(buildSettings.match(otherSettings)).equal(true); + }); + + it('should not match against current build settings when nodeVersion is null', () => { + const buildSettings = BuildSettings.current(); + const otherSettings = new BuildSettings('rustc-version', null, env); + expect(buildSettings.match(otherSettings)).equal(false); + }) + }); + + describe('serialize', () => { + it('should work when nodeVersion is null', () => { + + }) + }) + + describe('current build settings', () => { + it('should return values of expected types', () => { + // @ts-ignore + const { nodeVersion, env, rustc } = BuildSettings.current(); + expect(nodeVersion).to.be.a('string'); + expect(rustc).to.be.a('string'); + expect(env).to.deep.equal({ + npm_config_target: process.env.npm_config_target || null, + npm_config_arch: process.env.npm_config_arch || null, + npm_config_target_arch: process.env.npm_config_target_arch || null, + npm_config_disturl: process.env.npm_config_disturl || null, + npm_config_runtime: process.env.npm_config_runtime || null, + npm_config_build_from_source: process.env.npm_config_build_from_source || null, + npm_config_devdir: process.env.npm_config_devdir || null + }); + }); + }); + + describe('get node version', () => { + it('should return a string', () => { + expect(BuildSettings.getNodeVersion()).to.be.a('string'); + }); + }); + + describe('serialize and deserialize', () => { + it('should be equal when nodeVersion is null', () => { + expect(JSON.stringify(BuildSettings.fromJSON({ + rustc: 'rustc-version', + env + }))).equal(JSON.stringify(new BuildSettings( + 'rustc-version', + null, + env + ).toJSON())); + }); + }) +});