-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(): create tests for npmscripts util.
- Loading branch information
Showing
3 changed files
with
133 additions
and
3 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,53 @@ | ||
{ | ||
"name": "ionic-hello-world", | ||
"author": "Ionic Framework", | ||
"homepage": "http://ionicframework.com/", | ||
"scripts": { | ||
"ionic:build": "ionic-app-scripts build", | ||
"watch": "ionic-app-scripts watch", | ||
"ionic:test": "dir", | ||
"serve:before": "watch", | ||
"emulate:before": "build", | ||
"deploy:before": "build", | ||
"build:before": "build", | ||
"run:before": "build" | ||
}, | ||
"dependencies": { | ||
"@angular/common": "^2.0.0", | ||
"@angular/compiler": "^2.0.0", | ||
"@angular/compiler-cli": "0.6.2", | ||
"@angular/core": "^2.0.0", | ||
"@angular/forms": "^2.0.0", | ||
"@angular/http": "^2.0.0", | ||
"@angular/platform-browser": "^2.0.0", | ||
"@angular/platform-browser-dynamic": "^2.0.0", | ||
"@angular/platform-server": "^2.0.0", | ||
"@ionic/storage": "^1.0.3", | ||
"ionic-angular": "^2.0.0-rc.1", | ||
"ionic-native": "^2.2.3", | ||
"ionicons": "^3.0.0", | ||
"rxjs": "5.0.0-beta.12", | ||
"zone.js": "^0.6.21" | ||
}, | ||
"devDependencies": { | ||
"@ionic/app-scripts": "^0.0.36", | ||
"typescript": "^2.0.3" | ||
}, | ||
"cordovaPlugins": [ | ||
"cordova-plugin-whitelist", | ||
"cordova-plugin-statusbar", | ||
"cordova-plugin-console", | ||
"cordova-plugin-device", | ||
"cordova-plugin-splashscreen", | ||
"ionic-plugin-keyboard" | ||
], | ||
"cordovaPlatforms": [ | ||
"ios", | ||
{ | ||
"platform": "ios", | ||
"version": "", | ||
"locator": "ios" | ||
} | ||
], | ||
"description": "hi: An Ionic project" | ||
} |
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,73 @@ | ||
'use strict'; | ||
|
||
var rewire = require('rewire'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var npmScripts = rewire('../../lib/utils/npmScripts'); | ||
var EventEmitter = require('events'); | ||
var Q = require('q'); | ||
var spawn = require('cross-spawn-async'); | ||
|
||
describe('hasIonicScript function', function() { | ||
|
||
it('should return false if script does not exist', function(done) { | ||
var jsonContent = require(path.join(__dirname, '../', 'fixtures/', 'package.json')); | ||
var getPackageJsonContentsSpy = jasmine.createSpy('getPackageJsonContentsSpy').andReturn(Q(jsonContent)); | ||
var revert = npmScripts.__set__('getPackageJsonContents', getPackageJsonContentsSpy); | ||
spyOn(npmScripts, 'getPackageJsonContents').andReturn(Q(jsonContent)); | ||
|
||
npmScripts.hasIonicScript('stuff').then(function(results) { | ||
expect(results).toEqual(false); | ||
done(); | ||
revert(); | ||
}); | ||
}); | ||
it('should return true if script does not exist', function(done) { | ||
var jsonContent = require(path.join(__dirname, '../', 'fixtures/', 'package.json')); | ||
var getPackageJsonContentsSpy = jasmine.createSpy('getPackageJsonContentsSpy').andReturn(Q(jsonContent)); | ||
var revert = npmScripts.__set__('getPackageJsonContents', getPackageJsonContentsSpy); | ||
spyOn(npmScripts, 'getPackageJsonContents').andReturn(Q(jsonContent)); | ||
|
||
npmScripts.hasIonicScript('build').then(function(results) { | ||
expect(results).toEqual(true); | ||
done(); | ||
revert(); | ||
}); | ||
}); | ||
}); | ||
/* | ||
describe('runIonicScript function', function() { | ||
it('should call spawn', function(done) { | ||
//'npm', ['run', scriptName].concat(argv || []), { stdio: 'inherit' } | ||
var emitter = new EventEmitter(); | ||
var error = new Error(); | ||
spawn = jasmine.createSpy('spawnSpy', spawn).andCallFake(function() { | ||
return emitter; | ||
}); | ||
npmScripts.runIonicScript('test').catch(function(err) { | ||
expect(err).toEqual(error); | ||
done(); | ||
}); | ||
emitter.emit('error', error); | ||
}); | ||
}); | ||
*/ | ||
describe('getPackageJsonContents method', function() { | ||
it('getPackageJsonContents should return json contents of package.json file and should memoize', function(done) { | ||
var dapath = path.join(__dirname, '../', 'fixtures/package.json'); | ||
spyOn(path, 'resolve').andReturn(dapath); | ||
spyOn(fs, 'readFile').andCallThrough(); | ||
|
||
npmScripts.getPackageJsonContents().then(function(contents) { | ||
expect(contents).toEqual(require(dapath)); | ||
|
||
npmScripts.getPackageJsonContents().then(function(secondContents) { | ||
expect(secondContents).toEqual(require(dapath)); | ||
expect(fs.readFile.calls.length).toEqual(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |