From 5c26c0ad011b747aedf123c1d8f3f0fcb0072b8d Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Mon, 16 Jan 2017 12:44:54 +0100 Subject: [PATCH] Start setup of react-server-cli integration tests --- packages/react-server-cli/.gitignore | 1 + packages/react-server-cli/package.json | 15 ++++++++-- packages/react-server-cli/test/commands.js | 29 +++++++++++++++++++ .../commands/start-basic/in-files/routes.json | 4 +++ .../commands/start-basic/options.json | 3 ++ .../fixtures/commands/start-basic/stdout.txt | 0 .../commands/start-basic/test/.babelrc | 5 ++++ .../commands/start-basic/test/.reactserverrc | 9 ++++++ .../test/__clientTemp/build/manifest.json | 1 + .../start-basic/test/__clientTemp/entry.js | 18 ++++++++++++ .../test/__clientTemp/routes_client.js | 14 +++++++++ ...server_6d801a5f358c784222af96dab4833c21.js | 14 +++++++++ .../commands/start-basic/test/package.json | 19 ++++++++++++ .../commands/start-basic/test/routes.json | 4 +++ .../start-missing-routes/options.json | 3 ++ .../commands/start-missing-routes/stderr.txt | 0 .../in-files/.reactserverrc | 3 ++ .../commands/start-reactserverrc/options.json | 3 ++ .../commands/start-reactserverrc/stdout.txt | 0 .../in-files/routes.js | 1 + .../start-routes-with-error/options.json | 3 ++ .../start-routes-with-error/stderr.txt | 0 22 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 packages/react-server-cli/test/commands.js create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/in-files/routes.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/options.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/stdout.txt create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/.babelrc create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/.reactserverrc create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/build/manifest.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/entry.js create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_client.js create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_server_6d801a5f358c784222af96dab4833c21.js create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/package.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-basic/test/routes.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-missing-routes/options.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-missing-routes/stderr.txt create mode 100644 packages/react-server-cli/test/fixtures/commands/start-reactserverrc/in-files/.reactserverrc create mode 100644 packages/react-server-cli/test/fixtures/commands/start-reactserverrc/options.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-reactserverrc/stdout.txt create mode 100644 packages/react-server-cli/test/fixtures/commands/start-routes-with-error/in-files/routes.js create mode 100644 packages/react-server-cli/test/fixtures/commands/start-routes-with-error/options.json create mode 100644 packages/react-server-cli/test/fixtures/commands/start-routes-with-error/stderr.txt diff --git a/packages/react-server-cli/.gitignore b/packages/react-server-cli/.gitignore index 2c085d1d2..d4cc6d880 100644 --- a/packages/react-server-cli/.gitignore +++ b/packages/react-server-cli/.gitignore @@ -1,2 +1,3 @@ node_modules target +test/tmp diff --git a/packages/react-server-cli/package.json b/packages/react-server-cli/package.json index b6132d697..df7fe4683 100644 --- a/packages/react-server-cli/package.json +++ b/packages/react-server-cli/package.json @@ -7,7 +7,8 @@ "prepublish": "gulp", "lint": "gulp eslint", "test": "npm run ava && gulp test && nsp check", - "ava": "ava test", + "ava": "ava", + "ava-watch": "ava --watch", "clean": "rimraf target npm-debug.log*" }, "author": "Sasha Aickin", @@ -60,14 +61,22 @@ "gulp-babel": "^6.1.2", "gulp-eslint": "^3.0.1", "nsp": "^2.6.2", + "react": "^15.4.2", + "react-dom": "^15.4.2", "react-hot-loader": "^1.3.1", + "react-server": "^0.5.1", "react-server-gulp-module-tagger": "^0.4.10", - "rimraf": "^2.5.4" + "rimraf": "^2.5.4", + "superagent": "^1.8.4" }, "ava": { "require": [ "babel-core/register" ], - "tap": true + "tap": true, + "files": [ + "test/**/*.js", + "!test/fixtures/*.js" + ] } } diff --git a/packages/react-server-cli/test/commands.js b/packages/react-server-cli/test/commands.js new file mode 100644 index 000000000..bf74b4b8a --- /dev/null +++ b/packages/react-server-cli/test/commands.js @@ -0,0 +1,29 @@ +import path from 'path'; +import fs from 'fs'; +import child_process from 'child_process'; +import test from 'ava'; +import rimraf from 'rimraf'; + +const tmpPath = path.join(__dirname, 'tmp'); + +// function clear(){ +// process.chdir(__dirname); +// if (fs.existsSync(tmpPath)) rimraf.sync(tmpPath); +// fs.mkdirSync(tmpPath); +// process.chdir(tmpPath); +// } + +test('test', async t => { + process.chdir(`${__dirname}/fixtures/commands/start-basic/in-files`); + const server = child_process.spawn(process.execPath, [path.join(__dirname, '..', 'bin', 'react-server-cli'), 'start']); + + server.stderr.on('data', stderr => process.stderr.write(stderr)); + server.stdout.on('data', stdout => process.stdout.write(stdout)); + + await new Promise(resolve => { + setTimeout(() => { + resolve(); + server.kill(); + }, 3000); + }); +}); diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/in-files/routes.json b/packages/react-server-cli/test/fixtures/commands/start-basic/in-files/routes.json new file mode 100644 index 000000000..c612b7739 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/in-files/routes.json @@ -0,0 +1,4 @@ +{ + "middleware": [], + "routes": {} +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/options.json b/packages/react-server-cli/test/fixtures/commands/start-basic/options.json new file mode 100644 index 000000000..b88b6806a --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/options.json @@ -0,0 +1,3 @@ +{ + "args": ["start"] +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/stdout.txt b/packages/react-server-cli/test/fixtures/commands/start-basic/stdout.txt new file mode 100644 index 000000000..e69de29bb diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/.babelrc b/packages/react-server-cli/test/fixtures/commands/start-basic/test/.babelrc new file mode 100644 index 000000000..777115958 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "react-server" + ] +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/.reactserverrc b/packages/react-server-cli/test/fixtures/commands/start-basic/test/.reactserverrc new file mode 100644 index 000000000..9ffdcce28 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/.reactserverrc @@ -0,0 +1,9 @@ +{ + "routesFile": "routes.json", + "port": 3000, + "env": { + "production": { + "port": 80 + } + } +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/build/manifest.json b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/build/manifest.json new file mode 100644 index 000000000..0eeb795ba --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/build/manifest.json @@ -0,0 +1 @@ +{"jsChunksByName":{"common":"common.bundle.js"},"jsChunksById":{"0":"common.bundle.js"},"cssChunksByName":{},"hash":"d8bf2572a3f704ae8f83"} \ No newline at end of file diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/entry.js b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/entry.js new file mode 100644 index 000000000..8e183077a --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/entry.js @@ -0,0 +1,18 @@ + + if (typeof window !== "undefined") { + window.__setReactServerBase = function(path) { + // according to http://webpack.github.io/docs/configuration.html#output-publicpath + // we should never set __webpack_public_path__ when hot module replacement is on. + if (!module.hot) { + __webpack_public_path__ = path; + } + window.__reactServerBase = path; + } + } + var reactServer = require("react-server"); + window.rfBootstrap = function() { + reactServer.logging.setLevel('main', "debug"); + reactServer.logging.setLevel('time', "fast"); + reactServer.logging.setLevel('gauge', "ok"); + new reactServer.ClientController({routes: require("./routes_client")}).init(); + } \ No newline at end of file diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_client.js b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_client.js new file mode 100644 index 000000000..7617d218d --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_client.js @@ -0,0 +1,14 @@ + +var manifest = undefined; +function unwrapEs6Module(module) { return module.__esModule ? module.default : module } +var coreJsMiddleware = require('/Users/karlhorky/projects/kaytcat-react-server/packages/react-server-cli/node_modules/react-server-core-middleware/index.js').coreJsMiddleware; +var coreCssMiddleware = require('/Users/karlhorky/projects/kaytcat-react-server/packages/react-server-cli/node_modules/react-server-core-middleware/index.js').coreCssMiddleware; +module.exports = { + middleware:[ + coreJsMiddleware(null, manifest), + coreCssMiddleware(null, manifest), + + ], + routes:{ + } +}; \ No newline at end of file diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_server_6d801a5f358c784222af96dab4833c21.js b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_server_6d801a5f358c784222af96dab4833c21.js new file mode 100644 index 000000000..6cc1cd7ba --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/__clientTemp/routes_server_6d801a5f358c784222af96dab4833c21.js @@ -0,0 +1,14 @@ + +var manifest = {"jsChunksByName":{"common":"common.bundle.js"},"jsChunksById":{"0":"common.bundle.js"},"cssChunksByName":{},"hash":"d8bf2572a3f704ae8f83"}; +function unwrapEs6Module(module) { return module.__esModule ? module.default : module } +var coreJsMiddleware = require('/Users/karlhorky/projects/kaytcat-react-server/packages/react-server-cli/node_modules/react-server-core-middleware/index.js').coreJsMiddleware; +var coreCssMiddleware = require('/Users/karlhorky/projects/kaytcat-react-server/packages/react-server-cli/node_modules/react-server-core-middleware/index.js').coreCssMiddleware; +module.exports = { + middleware:[ + coreJsMiddleware("http://localhost:3001/", manifest), + coreCssMiddleware("http://localhost:3001/", manifest), + + ], + routes:{ + } +}; \ No newline at end of file diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/package.json b/packages/react-server-cli/test/fixtures/commands/start-basic/test/package.json new file mode 100644 index 000000000..9617c4c54 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/package.json @@ -0,0 +1,19 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "babel-preset-react-server": "^0.4.10", + "react": "^15.4.2", + "react-dom": "^15.4.2", + "react-server": "^0.5.1", + "superagent": "^1.8.4" + } +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-basic/test/routes.json b/packages/react-server-cli/test/fixtures/commands/start-basic/test/routes.json new file mode 100644 index 000000000..c612b7739 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-basic/test/routes.json @@ -0,0 +1,4 @@ +{ + "middleware": [], + "routes": {} +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-missing-routes/options.json b/packages/react-server-cli/test/fixtures/commands/start-missing-routes/options.json new file mode 100644 index 000000000..b88b6806a --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-missing-routes/options.json @@ -0,0 +1,3 @@ +{ + "args": ["start"] +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-missing-routes/stderr.txt b/packages/react-server-cli/test/fixtures/commands/start-missing-routes/stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/in-files/.reactserverrc b/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/in-files/.reactserverrc new file mode 100644 index 000000000..adfc63588 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/in-files/.reactserverrc @@ -0,0 +1,3 @@ +{ + "routesFile": "routes.js" +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/options.json b/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/options.json new file mode 100644 index 000000000..b88b6806a --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/options.json @@ -0,0 +1,3 @@ +{ + "args": ["start"] +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/stdout.txt b/packages/react-server-cli/test/fixtures/commands/start-reactserverrc/stdout.txt new file mode 100644 index 000000000..e69de29bb diff --git a/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/in-files/routes.js b/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/in-files/routes.js new file mode 100644 index 000000000..60245c063 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/in-files/routes.js @@ -0,0 +1 @@ +undeclaredVariable(); diff --git a/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/options.json b/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/options.json new file mode 100644 index 000000000..e8d4f0462 --- /dev/null +++ b/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/options.json @@ -0,0 +1,3 @@ +{ + "args": ["start", "--routes-file", "routes.js"] +} diff --git a/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/stderr.txt b/packages/react-server-cli/test/fixtures/commands/start-routes-with-error/stderr.txt new file mode 100644 index 000000000..e69de29bb