diff --git a/.istanbul.yml b/.istanbul.yml index 33eb122..0ef547a 100644 --- a/.istanbul.yml +++ b/.istanbul.yml @@ -9,7 +9,7 @@ reporting: reports: - lcov - html - dir: ./cover/node + dir: ./cover/unit/node watermarks: statements: [50, 90] lines: [50, 90] diff --git a/karma.conf.babel.js b/karma.conf.babel.js index 9f2d5de..b1aab61 100644 --- a/karma.conf.babel.js +++ b/karma.conf.babel.js @@ -1,10 +1,14 @@ import webpackConfig from './webpack.config.babel'; +import path from 'path'; export default (config) => { + // test mode based on basePath parameter (eg. test/unit, test/functional) + const testDir = config.basePath ? path.basename(config.basePath) : 'unit'; + config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', + basePath: 'test/' + testDir, // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter @@ -12,16 +16,18 @@ export default (config) => { // list of files / patterns to load in the browser files: [ - 'test/unit/**/*.js' + '**/*.js' ], // list of files to exclude - exclude: [], + exclude: [ + 'helpers/**/*.js' + ], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - 'test/unit/**/*.js': ['webpack'] + '**/*.js': ['webpack'] }, // test results reporter to use @@ -64,7 +70,7 @@ export default (config) => { // Generate a coverage report in /cover/karma coverageReporter: { type: 'html', //produces a html document after code is run - dir: 'cover/browser/' //path to created html doc + dir: '../../cover/' + testDir + '/browser/' //path to created html doc }, // The current coverage threshold values. These should never drop. diff --git a/package.json b/package.json index aa36ae3..f945a1c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "test:node": "istanbul cover jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json", "test:browser": "karma start", "posttest:node": "istanbul check-coverage", + "functional-test": "npm run functional-test:node ; npm run functional-test:browser", + "functional-test:node": "istanbul cover --dir cover/functional/node jasmine JASMINE_CONFIG_PATH=test/functional/jasmine.json", + "functional-test:browser": "karma start --basePath test/functional/", "lint": "eslint ./", "prepublish": "nsp check; npm run build", "build": "babel src -d dist && webpack", @@ -32,6 +35,7 @@ "babel-cli": "^6.10.1", "babel-core": "^6.10.4", "babel-loader": "^6.2.4", + "babel-plugin-transform-inline-environment-variables": "^6.8.0", "babel-preset-es2015": "^6.9.0", "babel-register": "^6.9.0", "eslint": "^2.4.0", @@ -39,6 +43,8 @@ "fetch-mock": "^5.0.5", "istanbul": "^1.0.0-alpha.2", "jasmine": "^2.4.1", + "js-yaml": "^3.6.1", + "json-loader": "^0.5.4", "karma": "^1.1.1", "karma-chrome-launcher": "^1.0.1", "karma-coverage": "^1.1.0", @@ -47,7 +53,8 @@ "karma-threshold-reporter": "^0.1.15", "karma-webpack": "^1.7.0", "nsp": "^2.4.0", - "webpack": "^1.13.1" + "webpack": "^1.13.1", + "yaml-loader": "^0.4.0" }, "files": [ "dist" diff --git a/test/functional/helpers/cloudsConfig.js b/test/functional/helpers/cloudsConfig.js new file mode 100644 index 0000000..8e4274c --- /dev/null +++ b/test/functional/helpers/cloudsConfig.js @@ -0,0 +1,8 @@ +/*eslint no-sync: "off"*/ +import yaml from 'js-yaml'; +import fs from 'fs'; +import cloudsYamlPath from './cloudsYamlPath'; + +const clouds = yaml.safeLoad(fs.readFileSync(cloudsYamlPath, 'utf8')); + +export default clouds; diff --git a/test/functional/helpers/cloudsYamlPath.js b/test/functional/helpers/cloudsYamlPath.js new file mode 100644 index 0000000..64df69f --- /dev/null +++ b/test/functional/helpers/cloudsYamlPath.js @@ -0,0 +1,23 @@ +/*eslint no-process-env: "off", no-sync: "off"*/ +import fs from 'fs'; +import path from 'path'; + +const resolvePaths = [ + './clouds.yaml', + process.env.HOME + '/.config/openstack/clouds.yaml', + '/etc/openstack/clouds.yaml' +]; + +function fileExists(path) { + try { + fs.statSync(path); + return true; + } catch(err) { + return false; + } +} + +const cloudFiles = resolvePaths.filter(fileExists); + +export default cloudFiles.length > 0 ? path.resolve(cloudFiles[0]) : 'clouds.yaml'; + diff --git a/test/functional/indexTest.js b/test/functional/indexTest.js new file mode 100644 index 0000000..7f32936 --- /dev/null +++ b/test/functional/indexTest.js @@ -0,0 +1,23 @@ +import Test from "../../src/index"; +import config from "./helpers/cloudsConfig"; + +describe("Simple functional test", () => { + + it("should call keystone URL", (done) => { + const testKeystone = function(response) { + expect(response.status).toBe(200); + done(); + }; + + const failTest = function(error) { + expect(error).toBeUndefined(); + done(); + }; + + const t = new Test(); + t.getUrl(config.clouds.devstack.auth.auth_url + '/v2.0') + .then(testKeystone) + .catch(failTest); + }); + +}); diff --git a/test/functional/jasmine.json b/test/functional/jasmine.json new file mode 100644 index 0000000..3c46468 --- /dev/null +++ b/test/functional/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "test/functional", + "spec_files": [ + "**/*[tT]est.js" + ], + "helpers": [ + "../../node_modules/babel-register/lib/node.js" + ], + "stopSpecOnExpectationFailure": false, + "random": false +} diff --git a/test/unit/indexTest.js b/test/unit/indexTest.js index c13a23f..b1100ff 100644 --- a/test/unit/indexTest.js +++ b/test/unit/indexTest.js @@ -1,4 +1,4 @@ -import Test from "../../src/index.js"; +import Test from "../../src/index"; const FetchMock = require('fetch-mock'); diff --git a/webpack.config.babel.js b/webpack.config.babel.js index d33cd20..8c3be33 100644 --- a/webpack.config.babel.js +++ b/webpack.config.babel.js @@ -1,3 +1,6 @@ +import webpack from 'webpack'; +import cloudsYamlPath from './test/functional/helpers/cloudsYamlPath'; + export default { entry: ['./src/index.js'], output: { @@ -11,8 +14,15 @@ export default { { test: /\.js$/, loader: 'babel', - exclude: /node_modules/ + exclude: /node_modules/, + query: { + plugins: ['transform-inline-environment-variables'] + } } ] - } + }, + plugins: [ + new webpack.NormalModuleReplacementPlugin(/helpers\/cloudsConfig/, + 'json!yaml!' + cloudsYamlPath) + ] };