Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Aug 1, 2017
1 parent 3df9c0c commit 336a598
Show file tree
Hide file tree
Showing 20 changed files with 2,481 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function(grunt) {
'staticDefinitionFiles-dev': {
expand: true,
cwd: 'src',
src: [ '**/*.md' ],
src: [ '**/*.md', '**/*.json' ],
dest: '<%= devDirectory %>/src/'
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/android.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
2 changes: 1 addition & 1 deletion src/features/chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
2 changes: 1 addition & 1 deletion src/features/edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
2 changes: 1 addition & 1 deletion src/features/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
2 changes: 1 addition & 1 deletion src/features/ie11.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
2 changes: 1 addition & 1 deletion src/features/ios.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
6 changes: 3 additions & 3 deletions src/features/node.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"postmessage": true,
"raf": true,
"setimmediate": true,
"xhr": true,
"xhr2": true
}
"xhr": false,
"xhr2": false
}
2 changes: 1 addition & 1 deletion src/features/safari.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"setimmediate": true,
"xhr": true,
"xhr2": true
}
}
17 changes: 11 additions & 6 deletions src/getFeatures.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { readFileSync } from 'fs';
import { BuildArgs } from './main';

export type FeatureMap = { [feature: string]: boolean };

const packagePath = process.env.DOJO_CLI ? '.' : '@dojo/cli-build-webpack';
const isCli = !!process.env.DOJO_CLI;

/**
* A simple wrapper for require to return a `FeatureMap` from JSON
* @param mid MID to JSON file
*/
function resolve(mid: string): FeatureMap | undefined {
try {
const result: FeatureMap = require(mid);
let result: FeatureMap;
/* istanbul ignore if */
if (isCli) {
result = require(mid);
}
else {
result = JSON.parse(readFileSync((require as any).toUrl(mid), 'utf8'));
}
return result;
}
catch (e) { }
Expand All @@ -28,7 +36,7 @@ export default function getFeatures(args: Partial<BuildArgs>): FeatureMap {

const featureNames = Array.isArray(args.features) ? args.features : [ args.features ];
const features = featureNames
.map((name) => resolve(`${packagePath}/features/${name}.json`));
.map((name) => resolve(`./features/${name}.json`));

if (!features.every((exists) => !!exists)) {
features.forEach((exists, idx) => {
Expand All @@ -43,9 +51,6 @@ export default function getFeatures(args: Partial<BuildArgs>): FeatureMap {
// conflict with each other. Once a value conflicts, it is removed from the feature map.
const seenFeatures = new Set<string>();
return (features as FeatureMap[]).reduce((previous, current) => {
if (!current) {
return previous;
}
Object.keys(current).forEach((key) => {
if (!(key in previous) && !seenFeatures.has(key)) {
seenFeatures.add(key);
Expand Down
Loading

0 comments on commit 336a598

Please sign in to comment.