Skip to content

Commit

Permalink
rig up generated templates and test files
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid committed May 8, 2020
1 parent 96163d8 commit a2a19cb
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"files": [
"/src/*.js",
"/src/commands/",
"/src/generators/",
"/src/oclif/",
"/src/bin/",
"/src/bin/run.cmd",
Expand Down
26 changes: 16 additions & 10 deletions packages/cli/src/generators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const writeGitignore = (gen) => {
gen.fs.copy(gen.templatePath('gitignore'), gen.destinationPath('.gitignore'));
};

const writeGenericPackageJson = (gen, additionalDeps) => {
const writeGenericPackageJson = (gen, additionalDeps = {}) => {
gen.fs.writeJSON('package.json', {
name: gen.options.packageName,
version: '1.0.0',
Expand Down Expand Up @@ -57,21 +57,27 @@ const writeGenericIndex = (gen) => {
);
};

const authTypes = {
'basic-auth': 'basic',
'custom-auth': 'custom',
'digest-auth': 'digest',
'oauth1-trello': 'oauth1',
oauth2: 'oauth2',
'session-auth': 'session',
};

const writeGenericAuth = (gen) => {
const authType = {
'basic-auth': 'basic',
'custom-auth': 'custom',
'digest-auth': 'digest',
'oauth1-trello': 'oauth1',
oauth2: 'oauth2',
'session-auth': 'session',
}[gen.options.template];
const authType = authTypes[gen.options.template];
const content = authFilesCodegen[authType]();
gen.fs.write('authentication.js', content);
};

const writeGenericAuthTest = (gen) => {
gen.fs.write(path.join('test', 'authentication.js'), '// TODO\n');
const authType = authTypes[gen.options.template];
gen.fs.copyTpl(
gen.templatePath(`authTests/${authType || 'generic'}.test.js`),
gen.destinationPath('test/authentication.js')
);
};

// Write files for templates that demonstrate an auth type
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* globals describe, it, expect */

describe('addition ', () => {
it('should work', () => {
expect(1 + 1).toEqual(2);
});
});
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/cli/src/generators/templates/index.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
config: authentication,
befores = [],
afters = [],
} = require('authentication');
} = require('./authentication');

module.exports = {
// This is just shorthand to reference the installed dependencies you have.
Expand Down
40 changes: 35 additions & 5 deletions packages/cli/src/smoke-tests/smoke-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ const npmPack = () => {
return filename;
};

const npmInstall = (packagePath, workdir) => {
runCommand('npm', ['install', '--production', packagePath], {
cwd: workdir
});
const npmInstall = (packagePath, workdir, productionOnly = true) => {
runCommand(
'npm',
['install', productionOnly ? '--production' : '', packagePath].filter(
Boolean
),
{
cwd: workdir
}
);
};

describe('smoke tests - setup will take some time', () => {
describe.only('smoke tests - setup will take some time', () => {
const context = {
// Global context that will be available for all test cases in this test suite
package: {
Expand Down Expand Up @@ -177,4 +183,28 @@ describe('smoke tests - setup will take some time', () => {
const result = JSON.parse(stdout);
result.should.be.Array();
});

describe.only('init w/ auth (runs very slowly)', () => {
const testableAuthTypes = ['basic-auth'];

testableAuthTypes.forEach(authType => {
it('should test out of the box', () => {
const subfolder = `test-auth-${authType}`;
const subfolderPath = path.join(context.workdir, subfolder);
runCommand(context.cliBin, ['yo', subfolder, '-t', authType], {
cwd: context.workdir
});

// use yarn because it's faster, we'll be doing this a lot
runCommand('yarn', [], {
cwd: subfolderPath
});

// should not throw an error
runCommand(context.cliBin, ['test'], {
cwd: subfolderPath
});
});
});
});
});

0 comments on commit a2a19cb

Please sign in to comment.