Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): ensure test files can be run out of the box with jest #327

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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