From 3082d7e5f28a3818e9aa8be94b24f446665db7d0 Mon Sep 17 00:00:00 2001 From: Tomasz Lakomy Date: Thu, 27 Apr 2017 10:11:00 -0700 Subject: [PATCH] Cleaned up e2e tests out of unused imports etc. Summary: ## Motivation (required) I've noticed that there were some unused import statements in e2e tests and some minor code quality issues (like unintended `if` statement in `jest/prepareE2E.js`), this PR addresses that. ## Test Plan (required) `npm run tests` passes just fine Closes https://github.com/facebook/react-vr/pull/126 Reviewed By: mikearmstrong001 Differential Revision: D4957532 Pulled By: mikearmstrong001 fbshipit-source-id: 84bb031 --- EndToEnd/runner/MockWorker.js | 2 - EndToEnd/testapp/client.js | 3 +- EndToEnd/testapp/e2e.vr.js | 11 +-- jest/prepareE2E.js | 148 +++++++++++++++++----------------- 4 files changed, 76 insertions(+), 88 deletions(-) diff --git a/EndToEnd/runner/MockWorker.js b/EndToEnd/runner/MockWorker.js index ba6f7b53a..66e5726c1 100644 --- a/EndToEnd/runner/MockWorker.js +++ b/EndToEnd/runner/MockWorker.js @@ -7,8 +7,6 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -import fs from 'fs'; -import path from 'path'; import vm from 'vm'; import {_getObjectFromURL} from './MockURL'; diff --git a/EndToEnd/testapp/client.js b/EndToEnd/testapp/client.js index 73f06060a..9111360c3 100644 --- a/EndToEnd/testapp/client.js +++ b/EndToEnd/testapp/client.js @@ -4,8 +4,7 @@ function init(bundle, parent, options) { const vr = new VRInstance(bundle, 'End2End', parent, { ...options, }); - vr.render = function() { - }; + vr.render = function() {}; // Begin the animation loop vr.start(); window.vr = vr; diff --git a/EndToEnd/testapp/e2e.vr.js b/EndToEnd/testapp/e2e.vr.js index 1c61a4533..361a270d7 100644 --- a/EndToEnd/testapp/e2e.vr.js +++ b/EndToEnd/testapp/e2e.vr.js @@ -1,14 +1,7 @@ 'use strict'; import React from 'react'; -import { - AppRegistry, - asset, - NativeModules, - Pano, - Text, - View, -} from 'react-vr'; +import {AppRegistry, NativeModules, Text, View} from 'react-vr'; window.NativeModules = NativeModules; @@ -32,6 +25,6 @@ class End2End extends React.Component { ); } -}; +} AppRegistry.registerComponent('End2End', () => End2End); diff --git a/jest/prepareE2E.js b/jest/prepareE2E.js index 7e692efd7..e8c5fe19c 100644 --- a/jest/prepareE2E.js +++ b/jest/prepareE2E.js @@ -8,84 +8,82 @@ console.log('Running full test suite.'); console.log('If you want to skip the end-to-end tests, run `npm run test-unit`\n'); if (!process.env.SKIPBUILD) { + console.log('Building React VR apps for end-to-end testing.'); + console.log('If you don\'t want to do this for every test run, set SKIPBUILD=1.'); + console.log(' SKIPBUILD=1 npm test'); -console.log('Building React VR apps for end-to-end testing.'); -console.log('If you don\'t want to do this for every test run, set SKIPBUILD=1.'); -console.log(' SKIPBUILD=1 npm test'); + function buildScript(root, input, output) { + const cliLocation = require.resolve('react-native/local-cli/cli.js'); + const configLocation = path.resolve(root, 'rn-cli.config.js'); + return new Promise(function(resolve, reject) { + const npm = child_process.spawn( + (/^win/.test(process.platform) ? 'node.exe' : 'node'), + [ + cliLocation, + 'bundle', + '--entry-file', + input, + '--platform', + 'vr', + '--bundle-output', + output, + '--dev', + 'false', + '--config', + configLocation, + '--reset-cache' + ], + {stdio: 'inherit', cwd: root} + ); + npm.on('close', function(code) { + if (code !== 0) { + reject(code); + } + resolve(); + }); + }); + } -function buildScript(root, input, output) { - const cliLocation = require.resolve('react-native/local-cli/cli.js'); - const configLocation = path.resolve(root, 'rn-cli.config.js'); - return new Promise(function(resolve, reject) { - const npm = child_process.spawn( - (/^win/.test(process.platform) ? 'node.exe' : 'node'), - [ - cliLocation, - 'bundle', - '--entry-file', - input, - '--platform', - 'vr', - '--bundle-output', - output, - '--dev', - 'false', - '--config', - configLocation, - '--reset-cache' - ], - {stdio: 'inherit', cwd: root} - ); - npm.on('close', function(code) { - if (code !== 0) { - reject(code); + const rootDir = path.resolve(__dirname, '..', 'EndToEnd', 'testapp'); + + new Promise(function(resolve, reject) { + const buildDir = path.join(rootDir, 'build'); + try { + const stat = fs.statSync(buildDir); + if (stat.isDirectory()) { + return resolve(); + } + } catch (e) {} + fs.mkdir(path.join(rootDir, 'build'), function(err) { + if (err) { + console.log('Failed to create `testapp/build` directory'); + return reject(1); } resolve(); }); + }).then(function() { + return Promise.all([ + buildScript( + rootDir, + path.resolve(rootDir, 'e2e.vr.js'), + path.resolve(rootDir, 'build', 'e2e.bundle.js') + ), + buildScript( + rootDir, + path.resolve(rootDir, 'client.js'), + path.resolve(rootDir, 'build', 'client.bundle.js') + ), + ]); + }).then(function() { + console.log( + 'Production versions were successfully built.' + + 'They can be found at ' + path.resolve(rootDir, 'build') + ); + }).catch(function(err) { + console.log( + 'An error occurred during the bundling process. Exited with code ' + err + + '.\nLook at the packager output above to see what went wrong.' + ); + process.exit(1); }); -} - -const rootDir = path.resolve(__dirname, '..', 'EndToEnd', 'testapp'); - -new Promise(function(resolve, reject) { - const buildDir = path.join(rootDir, 'build'); - try { - const stat = fs.statSync(buildDir); - if (stat.isDirectory()) { - return resolve(); - } - } catch (e) {} - fs.mkdir(path.join(rootDir, 'build'), function(err) { - if (err) { - console.log('Failed to create `testapp/build` directory'); - return reject(1); - } - resolve(); - }); -}).then(function() { - return Promise.all([ - buildScript( - rootDir, - path.resolve(rootDir, 'e2e.vr.js'), - path.resolve(rootDir, 'build', 'e2e.bundle.js') - ), - buildScript( - rootDir, - path.resolve(rootDir, 'client.js'), - path.resolve(rootDir, 'build', 'client.bundle.js') - ), - ]); -}).then(function() { - console.log( - 'Production versions were successfully built.' + - 'They can be found at ' + path.resolve(rootDir, 'build') - ); -}).catch(function(err) { - console.log( - 'An error occurred during the bundling process. Exited with code ' + err + - '.\nLook at the packager output above to see what went wrong.' - ); - process.exit(1); -}); - -} +} \ No newline at end of file