-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b88c1e1
commit 08c5610
Showing
9 changed files
with
432 additions
and
239 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
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,191 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
/** | ||
* Holds data related to a specific test. | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const TestResult = require( './TestResult' ); | ||
const assert = require( 'assert' ); | ||
const _ = require( 'lodash' ); // eslint-disable-line | ||
|
||
// constants | ||
const TEST_TYPES = [ | ||
'lint', | ||
'build', | ||
'sim-test', | ||
'qunit-test', | ||
'pageload-test' | ||
]; | ||
|
||
class Test { | ||
/** | ||
* @param {Snapshot} snapshot | ||
* @param {Object} description - from listContinuousTests.js | ||
*/ | ||
constructor( snapshot, description ) { | ||
assert( Array.isArray( description.test ), 'Test descriptions should have a test-name array' ); | ||
assert( typeof description.type === 'string', 'Test descriptions should have a type' ); | ||
assert( TEST_TYPES.includes( description.type ), `Unknown type: ${description.type}` ); | ||
|
||
// @public {Snapshot} | ||
this.snapshot = snapshot; | ||
|
||
// @public {Array.<string>} | ||
this.names = description.test; | ||
|
||
// @public {string} | ||
this.type = description.type; | ||
|
||
// @public {Array.<TestResult>} | ||
this.results = []; | ||
|
||
// @public {string|null} | ||
this.repo = null; | ||
|
||
if ( this.type === 'lint' || this.type === 'build' ) { | ||
assert( typeof description.repo === 'string', `${this.type} tests should have a repo` ); | ||
|
||
this.repo = description.repo; | ||
} | ||
|
||
// @public {Array.<string>} | ||
this.brands = null; | ||
|
||
if ( this.type === 'build' ) { | ||
assert( Array.isArray( description.brands ), 'build tests should have a brands' ); | ||
|
||
this.brands = description.brands; | ||
} | ||
|
||
// @public {string|null} | ||
this.url = null; | ||
|
||
if ( this.type === 'sim-test' || this.type === 'qunit-test' || this.type === 'pageload-test' ) { | ||
assert( typeof description.url === 'string', `${this.type} tests should have a url` ); | ||
|
||
this.url = description.url; | ||
} | ||
|
||
// @public {string|null} | ||
this.queryParameters = null; | ||
|
||
if ( description.queryParameters ) { | ||
assert( typeof description.queryParameters === 'string', 'queryParameters should be a string if provided' ); | ||
this.queryParameters = description.queryParameters; | ||
} | ||
|
||
// @public {boolean} - If false, we won't send this test to browsers that only support es5 (IE11, etc.) | ||
this.es5 = false; | ||
|
||
if ( description.es5 ) { | ||
this.es5 = true; | ||
} | ||
|
||
// @public {Array.<string>} - The repos that need to be built before this test will be provided | ||
this.buildDependencies = []; | ||
|
||
if ( description.buildDependencies ) { | ||
assert( Array.isArray( description.buildDependencies ), 'buildDependencies should be an array' ); | ||
|
||
this.buildDependencies = description.buildDependencies; | ||
} | ||
|
||
// @public {boolean} - For server-side tests run only once | ||
this.complete = false; | ||
|
||
// @public {boolean} - For server-side tests run only once, indicating it was successful | ||
this.success = false; | ||
|
||
// @public {number} - For browser-side tests, the number of times we have sent this test to a browser | ||
this.count = 0; | ||
} | ||
|
||
/** | ||
* Records a test result | ||
* @public | ||
* | ||
* @param {boolean} passed | ||
* @param {string|null} [message] | ||
*/ | ||
recordResult( passed, message ) { | ||
this.results.push( new TestResult( this, passed, message ) ); | ||
} | ||
|
||
/** | ||
* Whether this test can be run locally. | ||
* @public | ||
* | ||
* @returns {boolean} | ||
*/ | ||
isLocallyAvailable() { | ||
return !this.complete && ( this.type === 'lint' || this.type === 'build' ); | ||
} | ||
|
||
/** | ||
* Whether this test can be run in a browser. | ||
* @public | ||
* | ||
* @param {booealn} es5Only | ||
* @returns {boolean} | ||
*/ | ||
isBrowserAvailable( es5Only ) { | ||
if ( this.type !== 'sim-test' && this.type !== 'qunit-test' && this.type !== 'pageload-test' ) { | ||
return false; | ||
} | ||
|
||
if ( es5Only && !this.es5 ) { | ||
return false; | ||
} | ||
|
||
if ( this.buildDependencies ) { | ||
for ( const repo of this.buildDependencies ) { | ||
const buildTest = _.find( this.snapshot.tests, test => test.type === 'build' && test.repo === repo ); | ||
|
||
if ( !buildTest || !buildTest.success ) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Returns the object sent to the browser for this test. | ||
* @public | ||
* | ||
* @returns {Object} | ||
*/ | ||
getObjectForBrowser() { | ||
assert( this.type === 'sim-test' || this.type === 'qunit-test' || this.type === 'pageload-test', 'Needs to be a browser test' ); | ||
|
||
const baseURL = `../../ct-snapshots/${this.snapshot.timestamp}`; | ||
let url; | ||
|
||
if ( this.type === 'sim-test' ) { | ||
url = 'sim-test.html?url=' + encodeURIComponent( `${baseURL}/${this.url}` ); | ||
|
||
if ( this.queryParameters ) { | ||
url += '&simQueryParameters=' + encodeURIComponent( this.queryParameters ); | ||
} | ||
} | ||
else if ( this.type === 'qunit-test' ) { | ||
url = 'qunit-test.html?url=' + encodeURIComponent( `${baseURL}/${this.url}` ); | ||
} | ||
else if ( this.type === 'pageload-test' ) { | ||
url = 'pageload-test.html?url=' + encodeURIComponent( `${baseURL}/${this.url}` ); | ||
} | ||
|
||
return { | ||
snapshotName: this.snapshot.name, | ||
test: this.names, | ||
url: url | ||
}; | ||
} | ||
} | ||
|
||
module.exports = Test; |
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,33 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
/** | ||
* Holds data related to a specific test result | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const assert = require( 'assert' ); | ||
|
||
class TestResult { | ||
/** | ||
* @param {Test} test | ||
* @param {boolean} passed | ||
* @param {string|null} [message] | ||
*/ | ||
constructor( test, passed, message ) { | ||
assert( typeof passed === 'boolean', 'passed should be a boolean' ); | ||
|
||
// @public {Test} | ||
this.test = test; | ||
|
||
// @public {boolean} | ||
this.passed = passed; | ||
|
||
// @public {string|null} | ||
this.message = message || null; | ||
} | ||
} | ||
|
||
module.exports = TestResult; |
Oops, something went wrong.