Guest User

Untitled

a guest
Feb 8th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. import spawn from 'cross-spawn'
  2.  
  3. // 1. start the dev server using production config
  4. process.env.NODE_ENV = 'testing'
  5.  
  6. let servers
  7.  
  8. function shutdown (result) {
  9. console.log('HERE', result)
  10. try {
  11. // Passing a negative PID to kill will terminate all child processes, not just the parent
  12. if (servers) process.kill(-servers.pid)
  13. } catch (e) {
  14. console.error('Unable to shutdown servers, may need to be killed manually')
  15. }
  16.  
  17. if (result) {
  18. console.error(result)
  19. process.exit(1)
  20. } else {
  21. process.exit(0)
  22. }
  23. }
  24.  
  25. function watch (child) {
  26. child.on('close', shutdown)
  27. child.on('disconnect', shutdown)
  28. child.on('error', shutdown)
  29. child.on('exit', shutdown)
  30. child.on('uncaughtException', shutdown)
  31. }
  32.  
  33. try {
  34. servers = spawn('yarn', ['run', 'dev-all'], { cwd: '..', stdio: 'inherit', detached: true })
  35. watch(servers)
  36.  
  37. // 2. run the nightwatch test suite against it
  38. // to run in additional browsers:
  39. // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
  40. // 2. add it to the --env flag below
  41. // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
  42. // For more information on Nightwatch's config file, see
  43. // http://nightwatchjs.org/guide#settings-file
  44. var opts = process.argv.slice(2)
  45. if (opts.indexOf('--config') === -1) {
  46. opts = opts.concat(['--config', 'e2e/nightwatch.conf.js'])
  47. }
  48. if (opts.indexOf('--env') === -1) {
  49. opts = opts.concat(['--env', 'chrome'])
  50. }
  51.  
  52. var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })
  53. watch(runner)
  54. watch(process)
  55. } catch (error) {
  56. shutdown(error)
  57. }
  58.  
  59. require('babel-register')
  60. var config = require('../../frontend/config')
  61.  
  62. // http://nightwatchjs.org/guide#settings-file
  63. module.exports = {
  64. src_folders: ['e2e/specs'],
  65. output_folder: 'e2e/reports',
  66. custom_assertions_path: ['e2e/custom-assertions'],
  67.  
  68. selenium: {
  69. start_process: true,
  70. server_path: 'node_modules/selenium-server/lib/runner/selenium-server-standalone-3.0.1.jar',
  71. host: '127.0.0.1',
  72. port: 4444,
  73. cli_args: {
  74. 'webdriver.chrome.driver': require('chromedriver').path
  75. }
  76. },
  77.  
  78. test_settings: {
  79. default: {
  80. selenium_port: 4444,
  81. selenium_host: 'localhost',
  82. silent: true,
  83. globals: {
  84. devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
  85. }
  86. },
  87.  
  88. chrome: {
  89. desiredCapabilities: {
  90. browserName: 'chrome',
  91. javascriptEnabled: true,
  92. acceptSslCerts: true
  93. }
  94. },
  95.  
  96. firefox: {
  97. desiredCapabilities: {
  98. browserName: 'firefox',
  99. javascriptEnabled: true,
  100. acceptSslCerts: true
  101. }
  102. }
  103. }
  104. }
  105.  
  106. import firebase from 'firebase-admin'
  107. import uuid from 'uuid'
  108.  
  109. import * as firebaseSettings from '../../../backend/src/firebase-settings'
  110.  
  111. const PASSWORD = 'toomanysecrets'
  112.  
  113. function createUser (user) {
  114. console.log('Creating user', user.uid)
  115. let db = firebase.database()
  116. return Promise.all([
  117. firebase.auth().createUser({
  118. uid: user.uid,
  119. email: user.email,
  120. emailVerified: true,
  121. displayName: user.fullName,
  122. password: PASSWORD
  123. }),
  124. db.ref('users').child(user.uid).set({
  125. email: user.email,
  126. fullName: user.fullName
  127. }),
  128. db.ref('roles').child(user.uid).set({
  129. instructor: false
  130. })
  131. ])
  132. }
  133.  
  134. function destroyUser (user) {
  135. if (!user) return
  136.  
  137. console.log('Removing user', user.uid)
  138. let db = firebase.database()
  139. try { db.ref('roles').child(user.uid).remove() } catch (e) {}
  140. try { db.ref('users').child(user.uid).remove() } catch (e) {}
  141. try { firebase.auth().deleteUser(user.uid) } catch (e) {}
  142. }
  143.  
  144. module.exports = {
  145. 'Sign In links exist': browser => {
  146. // automatically uses dev Server port from /config.index.js
  147. // default: http://localhost:8080
  148. // see nightwatch.conf.js
  149. const devServer = browser.globals.devServerURL
  150.  
  151. browser
  152. .url(devServer)
  153. .waitForElementVisible('#container', 5000)
  154.  
  155. browser.expect.element('.main-nav').to.be.present
  156. browser.expect.element('.main-nav a[href^='https://oauth.ais.msu.edu/oauth/authorize']').to.be.present
  157. browser.expect.element('.main-nav a[href^='/email-sign-in']').to.be.present
  158. browser.end()
  159. },
  160. 'Successful Sign In with Email shows dashboard': browser => {
  161. const devServer = browser.globals.devServerURL
  162.  
  163. firebase.initializeApp(firebaseSettings.appConfig)
  164.  
  165. let userId = uuid.v4()
  166. let user = {
  167. uid: userId,
  168. email: `${userId}@test.com`,
  169. fullName: 'Test User'
  170. }
  171.  
  172. createUser(user)
  173.  
  174. browser.url(devServer)
  175. .waitForElementVisible('.main-nav a[href^='/email-sign-in']', 5000)
  176. .click('.main-nav a[href^='/email-sign-in']')
  177. .waitForElementVisible('button', 5000)
  178. .setValue('input[type=text]', user.email)
  179. .setValue('input[type=password]', PASSWORD)
  180. .click('button')
  181. .waitForElementVisible('.main-nav a[href^='/sign-out']', 5000)
  182. .end(() => {
  183. destroyUser(user)
  184. })
  185. }
  186. }
  187.  
  188. grimlock:backend egillespie$ ps -ef | grep nightwatch
  189. 501 13087 13085 0 1:51AM ttys000 0:02.18 node ./node_modules/.bin/nightwatch --presets es2015,stage-0 --config e2e/nightwatch.conf.js --env chrome
  190.  
  191. browser.end(() => {
  192. destroyUser(user).then(() => {
  193. firebase.app().delete()
  194. })
  195. })
  196.  
  197. function destroyUser (user) {
  198. if (!user) return Promise.resolve()
  199.  
  200. let db = firebase.database()
  201. return Promise.all([
  202. db.ref('roles').child(user.uid).remove(),
  203. db.ref('users').child(user.uid).remove(),
  204. firebase.auth().deleteUser(user.uid)
  205. ])
  206. }
Add Comment
Please, Sign In to add comment