This repository has been archived by the owner on Feb 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from FountainJS/jsdom
Angular 2.0 & tests with jsdom
- Loading branch information
Showing
15 changed files
with
208 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule generator-fountain-angular2
updated
117 files
Submodule generator-fountain-eslint
updated
3 files
+6 −11 | generators/app/index.js | |
+1 −1 | test/app/index.writing.js | |
+1 −1 | test/utils.js |
Submodule generator-fountain-gulp
updated
3 files
+20 −1 | generators/app/index.js | |
+2 −2 | generators/app/templates/gulpfile.js | |
+21 −3 | test/app/index/index.babel.js |
Submodule generator-fountain-karma
updated
4 files
+6 −6 | generators/app/index.js | |
+2 −0 | generators/app/templates/gulp_tasks/karma.js | |
+15 −2 | generators/app/templates/src/index.spec.js | |
+6 −6 | test/app/index.js |
Submodule generator-fountain-react
updated
3 files
+1 −1 | README.md | |
+3 −3 | generators/app/index.js | |
+8 −2 | test/app/index.configuring.js |
Submodule generator-fountain-systemjs
updated
6 files
Submodule generator-fountain-tslint
updated
2 files
+1 −1 | generators/app/index.js | |
+1 −1 | test/app/index.js |
Submodule generator-fountain-vue
updated
4 files
+2 −2 | generators/app/index.js | |
+1 −6 | generators/todoMVC/index.js | |
+3 −3 | test/app/index.configuring.js | |
+1 −1 | test/todoMVC/index.js |
Submodule generator-fountain-webpack
updated
5 files
+1 −0 | .gitignore | |
+17 −16 | generators/app/conf.js | |
+5 −1 | generators/app/templates/conf/webpack.conf.js | |
+1 −0 | generators/app/templates/gulp_tasks/webpack.js | |
+131 −66 | test/app/conf.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
|
||
const jsdom = require('jsdom'); | ||
const expect = require('chai').expect; | ||
const spawn = require('cross-spawn'); | ||
|
||
exports.run = function run(url) { | ||
return new Promise((resolve, reject) => { | ||
const result = spawn.sync('node', [`${__dirname}/jsdom-runner`, url], {stdio: 'inherit'}); | ||
if (result.status === 0) { | ||
console.log('jsdom run success'); | ||
resolve(); | ||
} else { | ||
console.log('jsdom run failed', result); | ||
reject(); | ||
} | ||
}); | ||
}; | ||
|
||
exports.open = function open(url) { | ||
const virtualConsole = jsdom.createVirtualConsole().sendTo(console); | ||
|
||
virtualConsole.on('jsdomError', error => { | ||
console.error('jsdom Error', error.stack, error.detail); | ||
}); | ||
|
||
return new Promise((resolve, reject) => { | ||
jsdom.env({ | ||
url, | ||
virtualConsole, | ||
features: { | ||
FetchExternalResources: ['script'], | ||
ProcessExternalResources: ['script'] | ||
}, | ||
created(error, window) { | ||
console.log('jsdom started on URL', url); | ||
if (error) { | ||
console.log('jsdom en creation error', error.stack, error.detail); | ||
reject(); | ||
} | ||
window.addEventListener('error', event => { | ||
console.error("Script error", event.error.stack, event.error.detail); | ||
}); | ||
resolve(window); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
function wait(time) { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, time); | ||
}); | ||
} | ||
|
||
function waitFor(test, retryTime, attemptsMax) { | ||
console.log('[WaitFor] First try'); | ||
const firstResult = test(); | ||
if (firstResult.length > 0) { | ||
return Promise.resolve(firstResult); | ||
} | ||
let attempts = 1; | ||
function oneTry() { | ||
return wait(retryTime).then(() => { | ||
console.log('[WaitFor] Try', attempts); | ||
const result = test(); | ||
if (result.length > 0) { | ||
return result; | ||
} | ||
attempts++; | ||
if (attempts >= attemptsMax) { | ||
throw new Error(`[WaitFor] Max attemps reached (${attemptsMax})`); | ||
} | ||
return oneTry(); | ||
}); | ||
} | ||
return oneTry(); | ||
} | ||
|
||
exports.testTechs = function testTechs(window) { | ||
return waitFor(() => { | ||
return window.document.querySelectorAll('h3'); | ||
}, 1000, 20) | ||
.then( | ||
elements => { | ||
expect(elements.length).to.equal(8); | ||
}, | ||
error => { | ||
console.log('Test techs error', error.stack, error.detail); | ||
throw error; | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const jsdom = require('./jsdom-helper'); | ||
|
||
jsdom.open(process.argv[2]) | ||
.then(window => jsdom.testTechs(window)) | ||
.then( | ||
() => process.exit(0), | ||
error => { | ||
console.log('jsdom runner failed', error.stack, error.detail); | ||
process.exit(1); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
|
||
require('co-mocha'); | ||
const product = require('cartesian-product'); | ||
|
||
const gulp = require('./helpers/gulp-helper'); | ||
const yeoman = require('./helpers/yeoman-helper'); | ||
const linter = require('./helpers/linter-helper'); | ||
const unit = require('./helpers/unit-helper'); | ||
const jsdom = require('./helpers/jsdom-helper'); | ||
|
||
describe('fountain travis integration test with jsdom', function () { | ||
this.timeout(0); | ||
|
||
const combinations = product([ | ||
['react', 'angular1', 'angular2', 'vue'], | ||
['webpack', 'systemjs', 'inject'], | ||
['babel', 'js', 'typescript'] | ||
]) | ||
// Angular 2 and Bower are not supported right now | ||
.filter(combination => combination[0] !== 'angular2' || combination[1] !== 'inject') | ||
// Vue only with Webpack and Babel | ||
.filter(combination => combination[0] !== 'vue' || (combination[1] === 'webpack' && combination[2] === 'babel')); | ||
|
||
combinations.forEach(combination => { | ||
const options = { | ||
framework: combination[0], | ||
modules: combination[1], | ||
css: 'scss', | ||
js: combination[2], | ||
sample: 'techs', | ||
router: combination[0] === 'angular1' ? 'uirouter' : 'router', | ||
ci: 'travis' | ||
}; | ||
|
||
describe(`tests with ${options.framework}, ${options.modules}, ${options.js}`, () => { | ||
before(function * () { | ||
console.log(`travis_fold:start:${options.framework}-${options.modules}-${options.js}`); | ||
yield yeoman.prepare(); | ||
yield yeoman.run(options); | ||
}); | ||
|
||
it('test linter', function * () { | ||
yield linter.linterTest(options); | ||
}); | ||
|
||
it('run "gulp test"', function * () { | ||
const result = yield gulp.test(); | ||
unit.unitTests(result); | ||
}); | ||
|
||
it('run "gulp serve" and e2e on number of Techs listed', function * () { | ||
const url = yield gulp.serve(); | ||
yield jsdom.run(url); | ||
gulp.killServe(); | ||
}); | ||
|
||
it('run "gulp serve:dist" and e2e on number of Techs listed', function * () { | ||
const url = yield gulp.serveDist(); | ||
yield jsdom.run(url); | ||
gulp.killServe(); | ||
}); | ||
|
||
after(() => { | ||
console.log(`travis_fold:end:${options.framework}-${options.modules}-${options.js}`); | ||
}); | ||
}); | ||
}); | ||
}); |