This repository has been archived by the owner on Mar 26, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathutil.js
54 lines (45 loc) · 1.41 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
var path = require('path');
var nock = require('nock');
var helpers = require('yeoman-generator').test;
function mockGitHub() {
nock.disableNetConnect();
nock('https://api.github.com')
.get('/repos/google/web-starter-kit/releases')
.reply(200, [{tag_name: 'v0.5.2'}]);
nock('https://github.com')
.filteringPath(/archive\/.*/, 'archive/zip')
.get('/google/web-starter-kit/archive/zip')
.replyWithFile(200, path.join(__dirname, 'data', 'wsk-0.5.2.zip'));
nock('https://raw.githubusercontent.com')
.get('/h5bp/server-configs-gae/master/app.yaml')
.replyWithFile(200, path.join(__dirname, 'data', 'app.yaml'));
}
function runGenerator(answers, opts, cb) {
answers = answers || {};
answers.siteName = answers.siteName || 'Test site';
answers.siteDescription = answers.siteDescription || 'Dummy desc';
answers.siteUrl = answers.siteUrl || 'http://test.example.org';
answers.layoutChoice = answers.layoutChoice || 'default';
if (typeof opts === 'function') {
cb = opts;
opts = null;
}
opts = opts || {
'skip-install': true,
quiet: true
};
helpers.run(path.join(__dirname, '../app'))
.inDir(path.join(__dirname, 'tmp'))
.withOptions(opts)
.withPrompt(answers)
.on('end', function () {
nock.cleanAll();
nock.enableNetConnect();
cb();
});
}
module.exports = {
mockGitHub: mockGitHub,
runGenerator: runGenerator
};