Skip to content
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
3 changes: 1 addition & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ test_script:
- npm --version
# run tests
- node_modules\.bin\grunt.cmd
- node_modules\.bin\grunt.cmd intern:node
- node_modules\.bin\grunt.cmd remapIstanbul:ci
- node_modules\.bin\grunt.cmd intern:node --test-reporter --color
- node_modules\.bin\grunt.cmd uploadCoverage

# Don't actually build.
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ deploy_key
.tscache
.tsconfig*.json
.history
coverage-unmapped.json
coverage-final.lcov
npm-debug.log
/_apidoc
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ install:
- travis_retry npm install
script:
- grunt
- grunt intern:node --combined
- grunt remapIstanbul:ci
- grunt intern:node --test-reporter
- grunt uploadCoverage
- grunt doc
notifications:
Expand Down
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = function (grunt) {
options: {
ignoreCompilerErrors: true // Remove this once compile errors are resolved
}
},
intern: {
version: 4
}
});

Expand Down
17 changes: 17 additions & 0 deletions intern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"environments": [
{ "browserName": "node" }
],

"suites": [
"./_build/tests/unit/all.js"
],

"coverage": [
"./_build/src/**/*.js"
],

"configs": {
"local": {}
}
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@
"glob": "^7.0.3",
"grunt": "~1.0.1",
"grunt-dojo2": "latest",
"intern": "^3.4.1",
"istanbul": "^0.4.3",
"intern": "~4.1.0",
"mockery": "^1.7.0",
"remap-istanbul": "^0.6.4",
"sinon": "^1.17.5",
"sinon-as-promised": "^4.0.2",
"typescript": "~2.4.1"
Expand Down
7 changes: 0 additions & 7 deletions tests/intern-local.ts

This file was deleted.

47 changes: 0 additions & 47 deletions tests/intern.ts

This file was deleted.

64 changes: 10 additions & 54 deletions tests/support/MockModule.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
import { RootRequire } from '@dojo/interfaces/loader';
declare const require: RootRequire;

import * as mockery from 'mockery';
import * as sinon from 'sinon';

const dojoNodePlugin = 'intern/dojo/node';

function load(modulePath: string): any {
const mid = `${dojoNodePlugin}!${modulePath}`;
return require(mid);
}

function unload(modulePath: string): void {
const abs = require.toUrl(modulePath);
const plugin = require.toAbsMid(dojoNodePlugin);
require.undef(`${plugin}!${abs}`);
}
import * as path from 'path';

function resolvePath(base: string, mid: string): string {
const isRelative = mid.match(/\.\//);
let result = base;
if (isRelative) {
if (mid.match(/^\.\//)) {
mid = mid.replace(/\.\//, '');
}
const up = mid.match(/^(\.\.\/)/);
if (up) {
const chunks = base.split('/');
chunks.splice(chunks.length - (up.length - 1));
result = chunks.join('/');
mid = mid.replace(/\.\.\//g, '');
}
mid = result + '/' + mid;
if (mid[0] !== '.') {
return mid;
}
return mid;
}

function getBasePath(modulePath: string): string {
const chunks = modulePath.split('/');
chunks.pop();
return chunks.join('/');
return path.resolve(base, mid);
}

export default class MockModule {
Expand All @@ -48,24 +15,18 @@ export default class MockModule {
private mocks: any;
private sandbox: sinon.SinonSandbox;

constructor(moduleUnderTestPath: string) {
this.basePath = getBasePath(moduleUnderTestPath);
this.moduleUnderTestPath = moduleUnderTestPath;
constructor(moduleUnderTestPath: string, require: NodeRequire) {
this.moduleUnderTestPath = require.resolve(moduleUnderTestPath);
this.basePath = path.dirname(this.moduleUnderTestPath);
this.sandbox = sinon.sandbox.create();
this.mocks = {};
}

dependencies(dependencies: string[]): void {
unload(this.moduleUnderTestPath);

dependencies
.map((dep) => resolvePath(this.basePath, dep))
.map((dep) => unload(dep));

dependencies.forEach((dependencyName) => {
let dependency;
try {
dependency = load(resolvePath(this.basePath, dependencyName));
dependency = require(resolvePath(this.basePath, dependencyName));
}
catch (e) {
dependency = {};
Expand Down Expand Up @@ -99,16 +60,11 @@ export default class MockModule {

getModuleUnderTest(): any {
mockery.enable({ warnOnUnregistered: false, useCleanCache: true });
const allowable = require.toUrl(this.moduleUnderTestPath) + '.js';
mockery.registerAllowable(allowable, true);
return load(this.moduleUnderTestPath);
mockery.registerAllowable(this.moduleUnderTestPath, true);
return require(this.moduleUnderTestPath);
}

destroy(): void {
unload(this.moduleUnderTestPath);
Object.keys(this.mocks)
.map((dep) => resolvePath(this.basePath, dep))
.map((dep) => unload(dep));
this.sandbox.restore();
mockery.deregisterAll();
mockery.disable();
Expand Down
13 changes: 7 additions & 6 deletions tests/support/testHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CommandWrapper} from '../../src/command';
import { stub } from 'sinon';
import { stub, spy } from 'sinon';

export type GroupDef = [{
groupName: string;
Expand All @@ -24,16 +24,17 @@ export function getCommandsMap(groupDef: GroupDef) {
groupDef.forEach((group) => {
group.commands.forEach((command) => {
const compositeKey = `${group.groupName}-${command.commandName}`;
const runStub = stub();
const runSpy = spy(() => command.fails ?
Promise.reject(new Error(compositeKey)) :
Promise.resolve(compositeKey)
);
const commandWrapper = {
name: command.commandName,
group: group.groupName,
description: compositeKey,
register: stub().callsArgWith(0, 'key', {}).returns(compositeKey),
runStub,
run: runStub.returns(command.fails ?
Promise.reject(new Error(compositeKey)) :
Promise.resolve(compositeKey))
runSpy,
run: runSpy
};
commands.set(compositeKey, commandWrapper);
});
Expand Down
Loading