Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

Test helper #169

Merged
merged 9 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
29 changes: 29 additions & 0 deletions lib/intern/internLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
declare const shimAmdDependencies: any;

// this file is loaded directly by intern, thus coverage is not available.
/* istanbul ignore next */
intern.registerLoader((options) => {
return intern.loadScript('node_modules/@dojo/loader/loader.js')
.then(() => intern.loadScript('node_modules/@dojo/shim/util/amd.js'))
.then(() => {
(<any> require).config(shimAmdDependencies({
baseUrl: options.baseUrl || intern.config.basePath,
packages: [
{'name': 'sinon', 'location': 'node_modules/sinon/pkg', 'main': 'sinon'}
]
}));

// load @dojo/shim/main to import the ts helpers
return new Promise<void>((resolve) => {
(<any> require)(['@dojo/shim/main'], () => {
resolve();
});
});
}).then(() => {
return (modules: string[]) => {
return new Promise<void>((resolve, reject) => {
(<any> require)(modules, () => resolve());
});
};
});
});
10 changes: 9 additions & 1 deletion options/intern.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import * as path from 'path';

export = function (grunt: IGrunt) {
grunt.loadNpmTasks('intern');

const progress = grunt.option<boolean>('progress');

// read the test config and find a loader. if no loader is specified, we need to add ours
const { browser: { loader: browserLoader = undefined } = {}, loader } = grunt.file.readJSON(path.resolve(grunt.config.get('internConfig')));

return {
options: {
config: '<%= internConfig %>',
reporters: [
{ name: 'runner', options: { 'hideSkipped': !progress, 'hidePassed': !progress } }
]
],
browser: (loader || browserLoader) ? {} : {
loader: './node_modules/grunt-dojo2/lib/intern/internLoader.js'
}
},
browserstack: {
options: {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import './tasks/uploadCoverage';
import './tasks/util/process';
import './tasks/util/postcss';
import './tasks/util/Publisher';
import './options/intern';
import './lib/load-dojo-loader';
69 changes: 69 additions & 0 deletions tests/unit/options/intern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { registerSuite } = intern.getInterface('object');
const { assert } = intern.getPlugin('chai');

import * as path from 'path';
import * as grunt from 'grunt';
import { getInputDirectory } from '../util';

const configPath = path.resolve(getInputDirectory() + '/intern.json');

registerSuite('options/intern', {
before() {
grunt.initConfig({
internConfig: configPath
});
},
afterEach() {
delete require.cache[require.resolve('../../../options/intern')];
},
tests: {
'uses loader specified in the intern config root'() {
const config = require('../../../options/intern')({
...grunt,
loadNpmTasks() {
},
file: {
readJSON() {
return {
loader: 'test'
};
}
}
});

assert.isTrue(config.options.browser.loader === undefined);
},
'uses loader specified in the intern browser config'() {
const config = require('../../../options/intern')({
...grunt,
loadNpmTasks() {
},
file: {
readJSON() {
return {
browser: {
loader: 'test'
}
};
}
}
});

assert.isTrue(config.options.browser.loader === undefined);
},
'injects loader if its empty'() {
const config = require('../../../options/intern')({
...grunt,
loadNpmTasks() {
},
file: {
readJSON() {
return {};
}
}
});

assert.isTrue(config.options.browser.loader === './node_modules/grunt-dojo2/lib/intern/internLoader.js');
}
}
});