Skip to content

Commit

Permalink
fix(cli): ensure test files can be run out of the box with jest (#327)
Browse files Browse the repository at this point in the history
* ensure test files can be run out of the box with jest
  • Loading branch information
xavdid authored Feb 18, 2021
1 parent 924387a commit c4a6dc8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/cli/scaffold/test.template.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* globals describe it */
const should = require('should');
/* globals describe, expect, test, it */

const zapier = require('zapier-platform-core');

// Use this to make test calls into your app:
const App = require('../../index');
const appTester = zapier.createAppTester(App);
// read the `.env` file into the environment, if available
zapier.tools.env.inject();

describe('My App', () => {
it('should run <%= ACTION_PLURAL %>.<%= KEY %>', async () => {
describe('<%= ACTION_PLURAL %>.<%= KEY %>', () => {
it('should run', async () => {
const bundle = { inputData: {} };

const results = await appTester(App.<%= ACTION_PLURAL %>.<%= KEY %>.<%= MAYBE_RESOURCE %>operation.perform, bundle);
should.exist(results);
expect(results).toBeDefined();
// TODO: add more assertions
});
});
6 changes: 3 additions & 3 deletions packages/cli/src/oclif/commands/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const getLocalFilePath = (directory, actionKey) =>
const getFullActionFilePath = (directory, actionKey) =>
path.join(process.cwd(), getLocalFilePath(directory, actionKey));

const getFullActionFilePathWithExtension = (directory, actionKey) =>
`${getFullActionFilePath(directory, actionKey)}.js`;
const getFullActionFilePathWithExtension = (directory, actionKey, isTest) =>
`${getFullActionFilePath(directory, actionKey)}${isTest ? '.test' : ''}.js`;

class ScaffoldCommand extends BaseCommand {
async perform() {
Expand Down Expand Up @@ -86,7 +86,7 @@ class ScaffoldCommand extends BaseCommand {
await writeTemplateFile(
'test',
templateContext,
getFullActionFilePathWithExtension(newTestActionDir, actionKey),
getFullActionFilePathWithExtension(newTestActionDir, actionKey, true),
preventOverwrite
);
this.stopSpinner();
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/smoke-tests/smoke-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ describe('smoke tests - setup will take some time', () => {
const newTrigger = path.join(newAppDir, 'triggers', 'neat.js');
fs.existsSync(newTrigger).should.be.true();

const newTriggerTest = path.join(newAppDir, 'test', 'triggers', 'neat.js');
const newTriggerTest = path.join(
newAppDir,
'test',
'triggers',
'neat.test.js'
);
fs.existsSync(newTriggerTest).should.be.true();

const pkg = JSON.parse(
Expand Down

0 comments on commit c4a6dc8

Please sign in to comment.