Skip to content
This repository was archived by the owner on Feb 19, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Docs Archetype

# 4.0.0 (2016 Aug 11)
* Change how functional tests are configured, now via npm config
* Export baseUrl and baseDir instead of setting global variables

# 3.0.2 (2016 Jul 26)
* Add baseUrl to webdriverio config

Expand Down
4 changes: 2 additions & 2 deletions dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "builder-docs-archetype-dev",
"version": "3.0.2",
"version": "4.0.0",
"description": "An archetype for building static landing/documentation pages for our projects. (Development)",
"main": "index.js",
"scripts": {},
Expand Down Expand Up @@ -33,4 +33,4 @@
},
"homepage": "https://github.com/FormidableLabs/builder-docs-archetype#readme",
"peerDependencies": {}
}
}
66 changes: 37 additions & 29 deletions dev/spec-setup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/* eslint-disable global-require, no-console */
var fetch = require("node-fetch");
var rowdy = require("rowdy");
var defaults = require("lodash.defaultsdeep");
var MochaAdapter = rowdy.adapters.mocha;

var SERVER_HOST = "127.0.0.1";
var SERVER_PORT = "3000";
var BASE_URL = process.env.npm_package_config_test_func_base_url;
var BASE_DIR = process.env.npm_package_config_test_func_base_dir;
var SERVER_HOST = process.env.npm_package_config_test_func_server_host;
var SERVER_PORT = process.env.npm_package_config_test_func_server_port;
var DEV_SERVER_TIMEOUT = process.env.npm_package_config_test_func_dev_server_timeout;
var MODE = process.env.npm_package_config_test_func_mode;
var ELEM_WAIT = 200;

// Base directory for app on server, e.g., /open-source/victory
global.TEST_FUNC_BASE_DIR = process.env.TEST_FUNC_BASE_DIR || "";
// Full app server url, e.g., http://localhost:3000/open-source/victory
global.TEST_FUNC_BASE_URL = process.env.TEST_FUNC_BASE_URL || "http://" + SERVER_HOST + ":" + SERVER_PORT + global.TEST_FUNC_BASE_DIR;
/*
* Setup Rowdy/Webdriverio
*/

var base = require("rowdy/config");
var config = defaults({
Expand All @@ -21,26 +25,26 @@ var config = defaults({
default: {
remote: {
// http://webdriver.io/guide/getstarted/configuration.html#baseUrl
baseUrl: global.TEST_FUNC_BASE_URL
baseUrl: BASE_URL + BASE_DIR
}
}
}
}
}, base);
rowdy(config);

var adapter = new MochaAdapter();

var ELEM_WAIT = 200;
/*
* Setup Mocha adapter
*/

var MochaAdapter = rowdy.adapters.mocha;
var adapter = new MochaAdapter();
adapter.before();
adapter.beforeEach();

beforeEach(function () {
return adapter.client
.timeoutsImplicitWait(ELEM_WAIT); // Set timeout for waiting on elements.
// Set default timeout for waiting on elements.
return adapter.client.timeoutsImplicitWait(ELEM_WAIT);
});

adapter.afterEach();
adapter.after();

Expand All @@ -50,9 +54,9 @@ adapter.after();

var serveDev = function (cb) {
console.log("Starting dev server...");

var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");

var webpackCfg = require("builder-docs-archetype/config/webpack/webpack.config.dev");

var compiler = webpack(webpackCfg);
Expand All @@ -62,7 +66,14 @@ var serveDev = function (cb) {
historyApiFallback: true
});

wdsServer.listen(SERVER_PORT, SERVER_HOST, cb);
// How long the test should wait before giving up
this.timeout(DEV_SERVER_TIMEOUT);
wdsServer.listen(SERVER_PORT, SERVER_HOST, function () {
// When the dev server's ready, hit the root url to trigger bundle build
fetch("http://" + SERVER_HOST + ":" + SERVER_PORT + BASE_DIR + "/")
.then(function () { cb(); })
.catch(cb);
});
};

/*
Expand All @@ -75,28 +86,25 @@ var serveStatic = function (cb) {
var ecstatic = require("ecstatic");

http.createServer(
ecstatic({ root: "./build", baseDir: global.TEST_FUNC_BASE_DIR + "/" })
ecstatic({ root: "./build", baseDir: BASE_DIR + "/" })
).listen(SERVER_PORT, SERVER_HOST, cb);
};

/*
* Before tests run, determine URL and server needs
* Before tests run, start a server if necessary
*/

before(function (done) {
switch (process.env.TEST_FUNC) {
case "static": return serveStatic(done);
case "dev": return serveDev(done);
case "remote":
if (!process.env.TEST_FUNC_BASE_URL) {
console.warn("No TEST_FUNC_BASE_URL environment variable set. Defaulting to " +
global.TEST_FUNC_BASE_URL + "\n");
}
return done();
switch (MODE) {
case "static": return serveStatic.call(this, done);
case "dev": return serveDev.call(this, done);
}
console.log("Expecting remote server at " + BASE_URL + BASE_DIR);
return done();
});

module.exports = {
adapter: adapter
adapter: adapter,
baseDir: BASE_DIR,
baseUrl: BASE_URL
};
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"name": "builder-docs-archetype",
"version": "3.0.2",
"version": "4.0.0",
"description": "An archetype for building static landing/documentation pages for our projects.",
"main": "index.js",
"config": {
"test_func_mode": "dev",
"test_func_base_dir": "",
"test_func_base_url": "http://127.0.0.1:3000",
"test_func_dev_server_timeout": 20000,
"test_func_server_port": 3000,
"test_func_server_host": "127.0.0.1"
},
"scripts": {
"dev": "webpack-dev-server --port 3000 --config node_modules/builder-docs-archetype/config/webpack/webpack.config.dev.js",
"lint-react": "eslint --ext .js,.jsx src",
Expand All @@ -17,9 +25,9 @@
"open-static": "open http://localhost:8080",
"server-static": "ecstatic --port 8080 build",
"builder:check": "eslint config",
"test-func-remote": "TEST_FUNC=remote mocha --opts ./test/func/mocha.opts",
"test-func-static": "TEST_FUNC=static mocha --opts ./test/func/mocha.opts",
"test-func-dev": "TEST_FUNC=dev mocha --opts ./test/func/mocha.opts",
"test-func-remote": "npm_package_config_test_func_mode=remote mocha --opts ./test/func/mocha.opts",
"test-func-static": "npm_package_config_test_func_mode=static mocha --opts ./test/func/mocha.opts",
"test-func-dev": "npm_package_config_test_func_mode=dev mocha --opts ./test/func/mocha.opts",
"install-selenium": "selenium-standalone install"
},
"author": "Paula Lavalle <[email protected]>",
Expand All @@ -43,7 +51,8 @@
"builder-support": "^0.3.0",
"eslint": "^1.10.3",
"eslint-config-defaults": "^8.0.2",
"eslint-plugin-filenames": "^0.2.0"
"eslint-plugin-filenames": "^0.2.0",
"node-fetch": "^1.6.0"
},
"repository": {
"type": "git",
Expand Down