Skip to content

Commit

Permalink
#24
Browse files Browse the repository at this point in the history
* add prompt tests
* rename test to reflect what the test is for
* add tests for github task
  • Loading branch information
JayGray committed May 20, 2014
1 parent 63f06bc commit e27455b
Showing 1 changed file with 133 additions and 3 deletions.
136 changes: 133 additions & 3 deletions test/test-creation.js
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var temp = require('temp');
var helpers = require('yeoman-generator').test;
var assert = require('yeoman-generator').assert;
var fs = require('fs-extra');

describe('Test prompt validations', function () {

Expand Down Expand Up @@ -45,8 +46,137 @@ describe('Test prompt validations', function () {
});
});

describe('Test github prompt', function(){
var app;

after(function () {
temp.cleanup();
});

it('Should retrieve github information for given name if user exists', function (done) {
var workspace = temp.mkdirSync();
helpers.testDirectory(workspace, function (err) {
if (err) {
return done(err);
}

app = helpers.createGenerator('node-webkit:app', [
path.resolve(__dirname, '../app')
]);

helpers.mockPrompt(app, {
'appName': 'TestApp',
'appDescription': 'Test App Description',
'githubUser': 'JayGray',
downloadNodeWebkit: false,
'platforms': ['Linux64']
});
app.options['skip-install'] = true;
app.run({}, function () {
assert.ok(typeof app.prompt.errors === 'undefined', 'This should fail if the app name contains a space.');
assert.ok(app.github, 'This should fail if app.github is set to false.');
assert.ok(app.githubUser === 'JayGray', 'This should fail if app.githubUser is not "JayGray".');
assert.ok(app.realname === 'Jörg Weber', 'This should fail if the app.realname is not "Jörg Weber".');
assert.ok(app.githubUrl === 'https://github.com/JayGray', 'This should fail if the app.githubUrl is not "https://github.com/JayGray".');
done();
});
});
});

it('Should skip retrieving github information if given name is default', function (done) {
var workspace = temp.mkdirSync();
helpers.testDirectory(workspace, function (err) {
if (err) {
return done(err);
}

app = helpers.createGenerator('node-webkit:app', [
path.resolve(__dirname, '../app')
]);

helpers.mockPrompt(app, {
'appName': 'TestApp',
'appDescription': 'Test App Description',
'githubUser': 'someuser',
downloadNodeWebkit: false,
'platforms': ['Linux64']
});
app.options['skip-install'] = true;
app.run({}, function () {
assert.ok(typeof app.prompt.errors === 'undefined', 'This should fail if the app name contains a space.');
assert.strictEqual(app.github, false, 'This should fail if app.github is set to false.');
assert.strictEqual(app.githubUser, 'someuser', 'This should fail if app.githubUser is not "someuser".');
assert.strictEqual(app.realname, void 0, 'This should fail if the app.realname is not "undefined".');
assert.strictEqual(app.githubUrl, void 0, 'This should fail if the app.githubUrl is not "undefined".');
done();
});
});
});

it('Should set app.github to false if given name is not known by github', function (done) {
var workspace = temp.mkdirSync();
helpers.testDirectory(workspace, function (err) {
if (err) {
return done(err);
}

app = helpers.createGenerator('node-webkit:app', [
path.resolve(__dirname, '../app')
]);

helpers.mockPrompt(app, {
'appName': 'TestApp',
'appDescription': 'Test App Description',
'githubUser': 'HopefullyNotExistingUser',
downloadNodeWebkit: false,
'platforms': ['Linux64']
});
app.options['skip-install'] = true;
app.run({}, function () {
assert.ok(typeof app.prompt.errors === 'undefined', 'This should fail if the app name contains a space.');
assert.strictEqual(app.github, false, 'This should fail if app.github is set to true.');
assert.strictEqual(app.githubUser, 'HopefullyNotExistingUser', 'This should fail if app.githubUser is not "HopefullyNotExistingUser".');
assert.strictEqual(app.realname, void 0, 'This should fail if the app.realname is not "undefined".');
assert.strictEqual(app.githubUrl, void 0, 'This should fail if the app.githubUrl is not "undefined".');
done();
});
});
});

it('Should write retrieved github informations correct in package.json', function (done) {
var workspace = temp.mkdirSync();
helpers.testDirectory(workspace, function (err) {
if (err) {
return done(err);
}

app = helpers.createGenerator('node-webkit:app', [
path.resolve(__dirname, '../app')
]);

helpers.mockPrompt(app, {
'appName': 'TestApp',
'appDescription': 'Test App Description',
'githubUser': 'JayGray',
downloadNodeWebkit: false,
'platforms': ['Linux64']
});
app.options['skip-install'] = true;
app.run({}, function () {
var packageJson = fs.readJsonFileSync('package.json');
console.log(packageJson);
assert.equal(packageJson.author.name, 'Jörg Weber', 'Should fail if author name is not "Jörg Weber"');
assert.equal(packageJson.author.url, 'https://github.com/JayGray', 'Should fail if author url is not "https://github.com/JayGray"');
assert.equal(packageJson.homepage, 'https://github.com/JayGray/testapp', 'Should fail if homepage is not "https://github.com/JayGray/testapp"');
assert.equal(packageJson.bugs, 'https://github.com/JayGray/testapp/issues', 'Should fail if bugs url is not "https://github.com/JayGray/testapp"');
done();
});
});
});
});


describe('node-webkit generator', function () {
describe('Test file creation', function () {
var app;

after(function () {
Expand Down Expand Up @@ -83,7 +213,7 @@ describe('node-webkit generator', function () {
];

app.run({}, function () {
assert.ok(typeof app.errors === 'undefined', 'Validation errors in prompt values');
assert.ok(typeof app.prompt.errors === 'undefined', 'Validation errors in prompt values');
helpers.assertFile(expected);
done();
});
Expand All @@ -98,7 +228,7 @@ describe('node-webkit generator', function () {
];

app.run({}, function () {
assert.ok(typeof app.errors === 'undefined', 'Validation errors in prompt values');
assert.ok(typeof app.prompt.errors === 'undefined', 'Validation errors in prompt values');
helpers.assertFile(expected);
done();
});
Expand Down

1 comment on commit e27455b

@mschaaf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
  "version": "0.2.0",
  "approved": true,
  "approver": "mschaaf",
  "approvalDate": 1400741112215
}

Please sign in to comment.