Skip to content

Commit

Permalink
test: update verbose flag to filter spinner output, update flag name (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jhockett authored and cjihrig-aws committed Jul 12, 2021
1 parent 1b0ec2b commit 59ab56a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 16 additions & 11 deletions packages/amplify-e2e-core/src/utils/nexpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare global {
}
}

import { isRegExp, format } from 'util';
import { types, format } from 'util';
import { Recorder } from '../asciinema-recorder';
import { AssertionError } from 'assert';
import strip = require('strip-ansi');
Expand Down Expand Up @@ -189,34 +189,34 @@ function chain(context: Context): ExecutionContext {
return chain(context);
},
sendKeyDown: function (repeat?: number): ExecutionContext {
const repeatitions = repeat ? Math.max(1, repeat) : 1;
const repetitions = repeat ? Math.max(1, repeat) : 1;
var _send: ExecutionStep = {
fn: () => {
for (let i = 0; i < repeatitions; i++) {
for (let i = 0; i < repetitions; ++i) {
context.process.write(KEY_DOWN_ARROW);
}
return true;
},
name: '_send',
shift: true,
description: `'[send] <Down> (${repeatitions})`,
description: `'[send] <Down> (${repetitions})`,
requiresInput: false,
};
context.queue.push(_send);
return chain(context);
},
sendKeyUp: function (repeat?: number): ExecutionContext {
const repeatitions = repeat ? Math.max(1, repeat) : 1;
const repetitions = repeat ? Math.max(1, repeat) : 1;
var _send: ExecutionStep = {
fn: () => {
for (let i = 0; i < repeatitions; i++) {
for (let i = 0; i < repetitions; ++i) {
context.process.write(KEY_UP_ARROW);
}
return true;
},
name: '_send',
shift: true,
description: `'[send] <Up> (${repeatitions})`,
description: `'[send] <Up> (${repetitions})`,
requiresInput: false,
};
context.queue.push(_send);
Expand Down Expand Up @@ -454,9 +454,14 @@ function chain(context: Context): ExecutionContext {
function onLine(data: string | Buffer) {
noOutputTimer.reschedule(context.noOutputTimeout);
data = data.toString();
if (process.env && process.env.VERBOSE_LOGGING_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) {
console.log(data);

if (process.env && process.env.VERBOSE_LOGGING_DO_NOT_USE_IN_CI_OR_YOU_WILL_BE_FIRED) {
const spinnerRegex = new RegExp(/.*(⠋|⠙|⠹|⠸|⠼|⠴|⠦|⠧|⠇|⠏).*/);
if (spinnerRegex.test(data) === false && strip(data).trim().length > 0) {
console.log(data);
}
}

if (context.stripColors) {
data = strip(data);
}
Expand Down Expand Up @@ -550,7 +555,7 @@ function chain(context: Context): ExecutionContext {
}

function testExpectation(data: string, expectation: string | RegExp, context: Context): boolean {
if (isRegExp(expectation)) {
if (types.isRegExp(expectation)) {
return expectation.test(data);
} else if (context.ignoreCase) {
return data.toLowerCase().indexOf(expectation.toLowerCase()) > -1;
Expand All @@ -574,7 +579,7 @@ function createUnexpectedEndError(message: string, remainingQueue: ExecutionStep

function createExpectationError(expected: string | RegExp, actual: string) {
var expectation;
if (isRegExp(expected)) {
if (types.isRegExp(expected)) {
expectation = 'to match ' + expected;
} else {
expectation = 'to contain ' + JSON.stringify(expected);
Expand Down
6 changes: 3 additions & 3 deletions packages/amplify-e2e-tests/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ npm run e2e __tests__/init.test.ts

E2E tests internally use a forked version of [nexpect](https://www.npmjs.com/package/nexpect) to run the CLI. There are helper methods that helps you to set up and delete project. The recommended pattern is to create a helper method that creates a resources as a helper method so these method could be used in other tests. For instance, `initJSProjectWithProfile` is a helper method that is used in `init` tests and also used in all the other tests to initalize a new Javascript project. The tests should have all the assertions to make sure the resource created by the helper method is setup correctly. We recommend using `aws-sdk` to make assert the resource configuration.

If you want to log the test results for debugging, set the environment variable `VERBOSE_LOGGING_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` to `true` and the output from the CLI will be printed on to the screen. Please refrain (as the variable name suggest) setting this in CI as test report will have all the CLI execution logs.
If you want to log the test results for debugging, set the environment variable `VERBOSE_LOGGING_DO_NOT_USE_IN_CI_OR_YOU_WILL_BE_FIRED` to `true` and the output from the CLI will be printed on to the screen. Please refrain (as the variable name suggest) setting this in CI as test report will have all the CLI execution logs.

```sh
env VERBOSE_LOGGING_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=true yarn e2e
env VERBOSE_LOGGING_DO_NOT_USE_IN_CI_OR_YOU_WILL_BE_FIRED=true yarn e2e
```

```typescript
import { initJSProjectWithProfile, deleteProject, amplifyPush } from '../init';
import { amplifyPush, deleteProject, initJSProjectWithProfile } from '../init';
import { createNewProjectDir, deleteProjectDir, getProjectMeta } from '../utils';

describe('amplify your test', () => {
Expand Down

0 comments on commit 59ab56a

Please sign in to comment.