From 8e7ad8948e21d459041b48ec14cd458939dc2cbb Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 10 May 2017 21:10:56 +0200 Subject: [PATCH] CB-12397 test updates before fix - factor out common artifact test code - check more configXml field values - check presence or absence of package.json - check absence of .gitignore - check presence or absence of .npmignore - cleanup remove trailing whitespaces --- spec/create.spec.js | 204 +++++++++++++++++++++++++++++--------------- 1 file changed, 134 insertions(+), 70 deletions(-) diff --git a/spec/create.spec.js b/spec/create.spec.js index f8db27eb..3b8c18e5 100644 --- a/spec/create.spec.js +++ b/spec/create.spec.js @@ -97,7 +97,7 @@ describe('cordova create checks for valid-identifier', function() { }) .fin(done); }, 60000); - + it('should reject reserved words from end of id', function(done) { create('projectPath', 'bob.class', 'appName', {}, events) .fail(function(err) { @@ -115,80 +115,73 @@ describe('create end-to-end', function() { shell.mkdir('-p', tmpDir); }); - afterEach(function() { process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows. shell.rm('-rf', tmpDir); }); - function checkProject() { + function checkCommonArtifacts() { // Check if top level dirs exist. var dirs = ['hooks', 'platforms', 'plugins', 'www']; dirs.forEach(function(d) { expect(path.join(project, d)).toExist(); }); - expect(path.join(project, 'hooks', 'README.md')).toExist(); + // index.js and template subdir folder should not exist + // (inner files should be copied to the project folder) + expect(path.join(project, 'index.js')).not.toExist(); + expect(path.join(project, 'template')).not.toExist(); + // Check if www files exist. expect(path.join(project, 'www', 'index.html')).toExist(); - // Check that config.xml was updated. - var configXml = new ConfigParser(path.join(project, 'config.xml')); - expect(configXml.packageName()).toEqual(appId); + // Check if config.xml exists. + expect(path.join(project, 'config.xml')).toExist(); - // TODO (kamrik): check somehow that we got the right config.xml from the fixture and not some place else. - // expect(configXml.name()).toEqual('TestBase'); + // Check that config.xml does not exist inside of www + expect(path.join(project, 'www', 'config.xml')).not.toExist(); } - function checkConfigXml() { - // Check if top level dirs exist. - var dirs = ['hooks', 'platforms', 'plugins', 'www']; - dirs.forEach(function(d) { - expect(path.join(project, d)).toExist(); - }); - expect(path.join(project, 'hooks', 'README.md')).toExist(); - - //index.js and template subdir folder should not exist (inner files should be copied to the project folder) - expect(path.join(project, 'index.js')).not.toExist(); - expect(path.join(project, 'template')).not.toExist(); + function checkCommonArtifactsAndConfigXml() { + checkCommonArtifacts(); - // Check if www files exist. - expect(path.join(project, 'www', 'index.html')).toExist(); + // Check that config.xml was updated. var configXml = new ConfigParser(path.join(project, 'config.xml')); expect(configXml.packageName()).toEqual(appId); expect(configXml.version()).toEqual('1.0.0'); + expect(configXml.name()).toEqual('TestBase'); + } - // Check that config.xml does not exist inside of www - expect(path.join(project, 'www', 'config.xml')).not.toExist(); + function checkArtifactsAndConfigXmlWithNoPackageFromWww() { + checkCommonArtifacts(); // Check that we got no package.json expect(path.join(project, 'package.json')).not.toExist(); + // Check that config.xml was updated. + var configXml = new ConfigParser(path.join(project, 'config.xml')); + expect(configXml.packageName()).toEqual(appId); + expect(configXml.version()).toEqual('1.0.0'); + expect(configXml.name()).toEqual('TestBase'); // Check that we got the right config.xml from the template and not stock expect(configXml.description()).toEqual('this is the correct config.xml'); } - function checkSubDir() { - // Check if top level dirs exist. - var dirs = ['hooks', 'platforms', 'plugins', 'www']; - dirs.forEach(function(d) { - expect(path.join(project, d)).toExist(); - }); - expect(path.join(project, 'hooks', 'README.md')).toExist(); - - //index.js and template subdir folder should not exist (inner files should be copied to the project folder) - expect(path.join(project, 'index.js')).not.toExist(); - expect(path.join(project, 'template')).not.toExist(); - - // Check if config files exist. - expect(path.join(project, 'www', 'index.html')).toExist(); + function checkArtifactsAndConfigXmlWithPackageFromSubDir() { + checkCommonArtifacts(); // Check that config.xml was updated. var configXml = new ConfigParser(path.join(project, 'config.xml')); expect(configXml.packageName()).toEqual(appId); expect(configXml.version()).toEqual('1.0.0'); + expect(configXml.name()).toEqual('TestBase'); + + // Check that config.xml does not exist inside of www + expect(path.join(project, 'www', 'config.xml')).not.toExist(); + delete require.cache[require.resolve(path.join(project, 'package.json'))]; + // Check that we got package.json (the correct one) var pkjson = require(path.join(project, 'package.json')); // Pkjson.displayName should equal config's name. @@ -206,8 +199,17 @@ describe('create end-to-end', function() { // Create a real project with no template // use default cordova-app-hello-world app return create(project, appId, appName, {}, events) - .then(checkProject) .then(function() { + // GENERAL NOTE: since checkCommonArtifactsAndConfigXml() is + // called from an explicit function any failure traceback + // will show where it was triggered from. + checkCommonArtifactsAndConfigXml(); + // Check that we got package.json + expect(path.join(project, 'package.json')).toExist(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).toExist(); + }).then(function() { delete require.cache[require.resolve(path.join(project, 'package.json'))]; var pkgJson = require(path.join(project, 'package.json')); //confirm default hello world app copies over package.json and it matched appId @@ -222,8 +224,14 @@ describe('create end-to-end', function() { it('should successfully run with Git URL', function(done) { // Create a real project with gitURL as template return create(project, appId, appName, configGit, events) - .then(checkProject) - .fail(function(err) { + .then(function() { + checkCommonArtifactsAndConfigXml(); + // Check that we got package.json + expect(path.join(project, 'package.json')).toExist(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).toExist(); + }).fail(function(err) { console.log(err && err.stack); expect(err).toBeUndefined(); }) @@ -236,8 +244,14 @@ describe('create end-to-end', function() { // tests cache clearing of npm template // uses phonegap-template-vue-f7-tabs return create(project, appId, appName, configNPMold) - .then(checkProject) .then(function() { + checkCommonArtifactsAndConfigXml(); + // Check that we got package.json + expect(path.join(project, 'package.json')).toExist(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).toExist(); + }).then(function() { shell.rm('-rf', project); delete require.cache[require.resolve(templatePkgJsonPath)]; var pkgJson = require(templatePkgJsonPath); @@ -252,8 +266,8 @@ describe('create end-to-end', function() { expect(err).toBeUndefined(); }) .fin(done); - }, 60000); - + }, 90000); + it('should successfully run with template not having a package.json at toplevel', function(done) { // Call cordova create with no args, should return help. var config = { @@ -267,8 +281,14 @@ describe('create end-to-end', function() { }; // Create a real project return create(project, appId, appName, config, events) - .then(checkProject) - .then(function(){ + .then(function() { + checkCommonArtifactsAndConfigXml(); + // Check that we got no package.json + expect(path.join(project, 'package.json')).not.toExist(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); + }).then(function() { // Check that we got the right config.xml var configXml = new ConfigParser(path.join(project, 'config.xml')); expect(configXml.description()).toEqual('this is the very correct config.xml'); @@ -279,7 +299,7 @@ describe('create end-to-end', function() { }) .fin(done); }, 60000); - + it('should successfully run with template having package.json and no sub directory', function(done) { // Call cordova create with no args, should return help. var config = { @@ -293,14 +313,20 @@ describe('create end-to-end', function() { }; // Create a real project return create(project, appId, appName, config, events) - .then(checkProject) - .fail(function(err) { + .then(function() { + checkCommonArtifactsAndConfigXml(); + // Check that we got no package.json + expect(path.join(project, 'package.json')).not.toExist(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); + }).fail(function(err) { console.log(err && err.stack); expect(err).toBeUndefined(); }) .fin(done); }, 60000); - + it('should successfully run with template having package.json, and subdirectory, and no package.json in subdirectory', function(done) { // Call cordova create with no args, should return help. var config = { @@ -315,21 +341,30 @@ describe('create end-to-end', function() { // Create a real project return create(project, appId, appName, config, events) - .then(checkProject) - .fail(function(err) { + .then(function() { + checkCommonArtifactsAndConfigXml(); + // Check that we got no package.json + expect(path.join(project, 'package.json')).not.toExist(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); + }).fail(function(err) { console.log(err && err.stack); expect(err).toBeUndefined(); }) .fin(done); }, 60000); - it('should successfully run with template having package.json, and subdirectory, and package.json in subdirectory', function(done) { // Call cordova create with no args, should return help. var config = configSubDirPkgJson; return create(project, appId, appName, config, events) - .then(checkSubDir) - .fail(function(err) { + .then(function() { + checkArtifactsAndConfigXmlWithPackageFromSubDir(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); + }).fail(function(err) { console.log(err && err.stack); expect(err).toBeUndefined(); }) @@ -341,8 +376,12 @@ describe('create end-to-end', function() { var config = configConfigInWww; // Create a real project return create(project, appId, appName, config, events) - .then(checkConfigXml) - .fail(function(err) { + .then(function() { + checkArtifactsAndConfigXmlWithNoPackageFromWww(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); + }).fail(function(err) { console.log(err && err.stack); expect(err).toBeUndefined(); }) @@ -360,8 +399,12 @@ describe('create end-to-end', function() { } }; return create(project, appId, appName, config, events) - .then(checkConfigXml) - .fail(function(err) { + .then(function() { + checkArtifactsAndConfigXmlWithNoPackageFromWww(); + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); + }).fail(function(err) { console.log(err && err.stack); expect(err).toBeUndefined(); }) @@ -380,10 +423,10 @@ describe('create end-to-end', function() { // Check if www files exist. expect(path.join(project, 'www', 'index.html')).toExist(); - - // Check www/config exists + + // Check www/config exists expect(path.join(project, 'www', 'config.xml')).toExist(); - // Check www/config.xml was not updated. + // Check www/config.xml was not updated. var configXml = new ConfigParser(path.join(project, 'www', 'config.xml')); expect(configXml.packageName()).toEqual('io.cordova.hellocordova'); expect(configXml.version()).toEqual('0.0.1'); @@ -393,18 +436,25 @@ describe('create end-to-end', function() { expect(path.join(project, 'config.xml')).toExist(); configXml = new ConfigParser(path.join(project, 'config.xml')); expect(configXml.description()).toEqual('this is the correct config.xml'); - // Check project/config.xml was updated. + // Check project/config.xml was updated. expect(configXml.packageName()).toEqual(appId); expect(configXml.version()).toEqual('1.0.0'); // Check that we got no package.json expect(path.join(project, 'package.json')).not.toExist(); - // Check that www is really a symlink, - // and project/config.xml , hooks and merges are not + // Check that www is really a symlink, and + // project/config.xml, hooks, & merges are not. expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true); expect(fs.lstatSync(path.join(project, 'hooks')).isSymbolicLink()).not.toBe(true); expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).not.toBe(true); + + // Check that we got no package.json + expect(path.join(project, 'package.json')).not.toExist(); + + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); } var config = { lib: { @@ -440,7 +490,7 @@ describe('create end-to-end', function() { expect(path.join(project, d)).toExist(); }); expect(path.join(project, 'hooks', 'README.md')).toExist(); - + //index.js and template subdir folder should not exist (inner files should be copied to the project folder) expect(path.join(project, 'index.js')).not.toExist(); expect(path.join(project, 'template')).not.toExist(); @@ -448,7 +498,7 @@ describe('create end-to-end', function() { // Check if www files exist. expect(path.join(project, 'www', 'index.html')).toExist(); - // Check that www, and config.xml is really a symlink + // Check that www, and config.xml are really symlinks. expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true); expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).toBe(true); @@ -456,16 +506,23 @@ describe('create end-to-end', function() { var configXml = new ConfigParser(path.join(project, 'config.xml')); expect(configXml.packageName()).toEqual('io.cordova.hellocordova'); expect(configXml.version()).toEqual('0.0.1'); - + // Check that we got the right config.xml expect(configXml.description()).toEqual('this is the correct config.xml'); - + delete require.cache[require.resolve(path.join(project, 'package.json'))]; // Check that we got package.json (the correct one) and it was changed var pkjson = require(path.join(project, 'package.json')); // Pkjson.name should equal config's id. expect(pkjson.name).toEqual(appId.toLowerCase()); expect(pkjson.valid).toEqual('true'); + + // Check that we got no package.json + expect(path.join(project, 'package.json')).not.toExist(); + + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); } var config = { lib: { @@ -515,6 +572,13 @@ describe('create end-to-end', function() { expect(fs.lstatSync(path.join(project, 'hooks')).isSymbolicLink()).toBe(true); expect(fs.lstatSync(path.join(project, 'merges')).isSymbolicLink()).toBe(true); expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).not.toBe(true); + + // Check that we got no package.json + expect(path.join(project, 'package.json')).not.toExist(); + + // CB-12397 check .gitignore behavior + expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.npmignore')).not.toExist(); } var config = { @@ -543,5 +607,5 @@ describe('create end-to-end', function() { .fin(done); }, 60000); - }); + }); });