Permalink
Browse files

test: add end to end tests

* Move unit tests to a nested folder.

This is needed to have them on the same level with e2e tests wich are yet to come.

* Install Nightwatch.js

* Add Nightwatch config

* Add a basic spec for editing JavaScript

* Add e2e npm script

* Install selenium-standalone, get the latest version post-install

* Run selenium automatically when running e2e tests

* Rewrite the test to avoid focus issues, on the standalone version of selenium

* Update the docs with instructions on how to run e2e tests

* Change JSBin -> JS Bin

* Move e2e specs into a nested folder

* Assert the URL is updated in the integration tests

I'm copying and pasting custom assertion from
https://github.com/maxgalbu/nightwatch-custom-commands-assertions

Alternative would be using npm install, but it's doesn't seem feasible here because we only need this one assertion.

Also custom assertions path would have point to the node_modules folder, which would make it hard to add custom assertions.

* Mention that JS Bin has to be running for integration tests to succeed in the docs

* Run e2e tests with travis-ci

* Do not run e2e for pull requests
  • Loading branch information...
1 parent 290a868 commit 8f224c0cd06c5413dece19462a7239b14c158a41 @kirjs kirjs committed with remy Aug 23, 2016
View
@@ -1,8 +1,16 @@
language: node_js
node_js:
- "0.10.40"
+addons:
+ sauce_connect: true
before_script:
- npm install
+ - test "$TRAVIS_PULL_REQUEST" = "false" && npm start&
+script:
+ - npm test
+ - test "$TRAVIS_PULL_REQUEST" = "false" && npm run e2e-remote
+ - test "$TRAVIS_PULL_REQUEST" = "false" && pkill node || exit 0
+
notifications:
email: false
irc:
@@ -103,3 +103,11 @@ Finally, ensure either the config.local.json's `env` property is set to "product
$ NODE_ENV=production node .
And that's it.
+
+
+## End-to-end tests
+JS Bin has end-to-end tests. The tests can be found in `tests/e2e` folder.
+
+Running the tests (JS Bin has to be running on port http://localhost:3000):
+
+ $ npm run e2e
View
@@ -0,0 +1,45 @@
+var glob = require('glob');
+var path = require('path');
+
+var seleniumJar = glob.sync(path.join(
+ 'node_modules', 'selenium-standalone', '.selenium', 'selenium-server', '*.jar'))[0];
+
+if (!seleniumJar) {
+ throw new Error('Can\'t find selenium jar, try running "npm run selenium:install"');
+}
+
+const TRAVIS_JOB_NUMBER = process.env.TRAVIS_JOB_NUMBER;
+
+module.exports = {
+ "src_folders": ["test/e2e/specs"],
+
+ "test_settings": {
+ "local": {
+ "launch_url": "http://localhost:3000/",
+ "selenium": {
+ "start_process": true,
+ "server_path": seleniumJar
+ }
+ },
+ "remote": {
+ desiredCapabilities: {
+ browserName: "chrome",
+ platform: "OS X 10.11",
+ version: "latest",
+ build: 'build-' + TRAVIS_JOB_NUMBER,
+ 'tunnel-identifier': TRAVIS_JOB_NUMBER,
+ "username": process.env.SAUCE_USERNAME,
+ "access_key": process.env.SAUCE_ACCESS_KEY
+ },
+ "launch_url": "http://localhost:3000/",
+ "selenium_port": 80,
+ "selenium_host": "ondemand.saucelabs.com",
+ "silent": true,
+ "screenshots": {
+ "enabled": false,
+ "path": ""
+ }
+ }
+ },
+ "custom_assertions_path": "test/e2e/assertions"
+};
View
@@ -19,14 +19,17 @@
},
"scripts": {
"start": "(sleep 2 && open http://localhost:3000) & ./bin/jsbin",
- "test": "node_modules/mocha/bin/_mocha -t 25000 --ui bdd test/**/*.test.js",
+ "test": "node_modules/mocha/bin/_mocha -t 25000 --ui bdd test/unit/**/*.test.js",
":install": "build/install.js",
- "postinstall": "grunt build",
+ "postinstall": "grunt build && npm run selenium:install",
"postversion": "git push origin master && git push --tags origin master",
"preupdate": "node build/pre-update.js",
"postupdate": "node build/post-update.js commit",
"snyk-protect": "snyk protect",
- "prepublish": "npm run snyk-protect"
+ "prepublish": "npm run snyk-protect",
+ "e2e": "nightwatch --env local --config nightwatch.js",
+ "e2e-remote": "nightwatch --env remote --config nightwatch.js",
+ "selenium:install": "selenium-standalone install"
},
"dependencies": {
"async": "~0.1.22",
@@ -74,16 +77,19 @@
"validator": "^3.16.1"
},
"devDependencies": {
+ "glob": "^7.0.5",
"grunt": "~0.4.1",
+ "grunt-cli": "~0.1.11",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-uglify": "~0.2.2",
- "should": "~1.2.2",
- "sinon": "~1.7.3",
- "grunt-cli": "~0.1.11",
- "mocha-casperjs": "~0.5.0",
"hbs-utils": "0.0.3",
- "mocha": "~1.21.4"
+ "mocha": "~1.21.4",
+ "mocha-casperjs": "~0.5.0",
+ "nightwatch": "^0.9.6",
+ "selenium-standalone": "^5.5.0",
+ "should": "~1.2.2",
+ "sinon": "~1.7.3"
},
"optionalDependencies": {
"zmq": "~2.6.0"
@@ -0,0 +1,48 @@
+'use strict';
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.assertion = assertion;
+
+var _util = require('util');
+
+var _util2 = _interopRequireDefault(_util);
+
+function _interopRequireDefault(obj){
+ return obj && obj.__esModule ? obj : {default: obj};
+}
+
+function assertion(regex, msg){
+ this.message = msg || _util2.default.format('Testing if the URL match the regex "%s".', regex);
+ this.expected = regex;
+
+ this.pass = function (value){
+ return this.expected.test(value);
+ };
+
+ this.value = function (result){
+ return result.value;
+ };
+
+ this.command = function (callback){
+ return this.api.url(callback);
+ };
+}
+/**
+ * Assert that the url matches the regex provided
+ *
+ * h3 Examples:
+ *
+ * browser
+ * .url("http://www.google.com")
+ * .assert.urlMatch(/\.com$/)
+ *
+ * browser
+ * .url("http://www.google.com")
+ * .assert.urlMatch(new RegExp("\.com$", "i")
+ *
+ * @author maxgalbu
+ * @param {RegExp} regex - regular expression
+ * @param {String} [msg] - output to identify the assertion
+ */
@@ -0,0 +1,16 @@
+module.exports = {
+ 'Basic JavaScript test' : function (client) {
+ client
+ .url(client.launch_url)
+ .waitForElementVisible('#panels a:nth-child(3)', 1000)
+ .click('#panels a:nth-child(3)')
+ .waitForElementVisible('.javascript .CodeMirror', 1000)
+ .execute(function (text){
+ return $('.javascript .CodeMirror')[0].CodeMirror.setValue(text);
+ }, ["document.body.innerHTML = 'Hello'"])
+ .frame(2)
+ .assert.containsText('body', 'Hello')
+ .assert.urlMatch(/\/\w+\/edit\?html,js,output$/)
+ .end();
+ }
+};
File renamed without changes.
File renamed without changes.

0 comments on commit 8f224c0

Please sign in to comment.