Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test-page option to the test command #4377

Merged
merged 1 commit into from
Jul 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = Command.extend({
{ name: 'module', type: String, description: 'The name of a test module to run', aliases: ['m'] },
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
{ name: 'launch', type: String, default: false, description: 'A comma separated list of browsers to launch for tests.' },
{ name: 'reporter', type: String, description: 'Test reporter to use [tap|dot|xunit]', aliases: ['r']}
{ name: 'reporter', type: String, description: 'Test reporter to use [tap|dot|xunit]', aliases: ['r']},
{ name: 'test-page', type: String, description: 'Test page to invoke'}
],

init: function() {
Expand All @@ -48,16 +49,18 @@ module.exports = Command.extend({
},

_generateCustomConfigFile: function(options) {
if (!options.filter && !options.module && !options.launch) { return options.configFile; }
if (!options.filter && !options.module && !options.launch && !options['test-page']) { return options.configFile; }

var tmpPath = this.quickTemp.makeOrRemake(this, '-customConfigFile');
var customPath = path.join(tmpPath, 'testem.json');
var originalContents = JSON.parse(fs.readFileSync(options.configFile, { encoding: 'utf8' }));

var containsQueryString = originalContents['test_page'].indexOf('?') > -1;

var testPage = options['test-page']?options['test-page']:originalContents['test_page'];

var containsQueryString = testPage.indexOf('?') > -1;
var testPageJoinChar = containsQueryString ? '&' : '?';

originalContents['test_page'] = originalContents['test_page'] + testPageJoinChar + this.buildTestPageQueryString(options);
originalContents['test_page'] = testPage + testPageJoinChar + this.buildTestPageQueryString(options);
if (options.launch) {
originalContents['launch'] = options.launch;
}
Expand Down
32 changes: 30 additions & 2 deletions tests/unit/commands/test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,19 @@ describe('test command', function() {
expect(existsSync(newPath));
});

it('should return the original path if filter or module or launch isn\'t present', function() {
it('should return the original path if options are not present', function() {
var originalPath = runOptions.configFile;
var newPath = command._generateCustomConfigFile(runOptions);

expect(newPath).to.equal(originalPath);
});

it('when module and filter and launch option is present the new file path returned exists', function() {
it('when options are present the new file path returned exists', function() {
var originalPath = runOptions.configFile;
runOptions.module = 'fooModule';
runOptions.filter = 'bar';
runOptions.launch = 'fooLauncher';
runOptions['test-page'] = 'foo/test.html?foo';
var newPath = command._generateCustomConfigFile(runOptions);

expect(newPath).to.not.equal(originalPath);
Expand Down Expand Up @@ -183,6 +184,15 @@ describe('test command', function() {
expect(existsSync(newPath), 'file should exist');
});

it('when test-page option is present the new file path returned exists', function() {
var originalPath = runOptions.configFile;
runOptions['test-page'] = 'foo/test.html?foo';
var newPath = command._generateCustomConfigFile(runOptions);

expect(newPath).to.not.equal(originalPath);
expect(existsSync(newPath), 'file should exist');
});

it('when provided filter and module the new file returned contains the both option values in test_page', function() {
runOptions.module = 'fooModule';
runOptions.filter = 'bar';
Expand All @@ -192,6 +202,24 @@ describe('test command', function() {
expect(contents['test_page']).to.be.equal('tests/index.html?module=fooModule&filter=bar');
});

it('when provided test-page the new file returned contains the value in test_page', function() {
runOptions['test-page'] = 'foo/test.html?foo';
var newPath = command._generateCustomConfigFile(runOptions);
var contents = JSON.parse(fs.readFileSync(newPath, { encoding: 'utf8' }));

expect(contents['test_page']).to.be.equal('foo/test.html?foo&');
});

it('when provided test-page with filter and module the new file returned contains those values in test_page', function() {
runOptions.module = 'fooModule';
runOptions.filter = 'bar';
runOptions['test-page'] = 'foo/test.html?foo';
var newPath = command._generateCustomConfigFile(runOptions);
var contents = JSON.parse(fs.readFileSync(newPath, { encoding: 'utf8' }));

expect(contents['test_page']).to.be.equal('foo/test.html?foo&module=fooModule&filter=bar');
});

it('when provided launch the new file returned contains the value in launch', function() {
runOptions.launch = 'fooLauncher';
var newPath = command._generateCustomConfigFile(runOptions);
Expand Down