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

test: fix test line trim #7872

Merged
merged 1 commit into from
Aug 3, 2021
Merged
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
45 changes: 8 additions & 37 deletions packages/amplify-prompts/src/__tests__/printer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AmplifyPrinter } from '../printer';
import os from 'os';
import * as flags from '../flags';
const writeStream_stub = ({
write: jest.fn(),
Expand All @@ -16,10 +15,6 @@ const testInput = 'this is a test line';

const printer = new AmplifyPrinter(writeStream_stub);

const os_mock = os as jest.Mocked<Writeable<typeof os>>;

os_mock.EOL = '\n';

beforeEach(() => {
jest.clearAllMocks();
flags_mock.isDebug = false;
Expand All @@ -30,10 +25,7 @@ beforeEach(() => {
it('prints debug lines when debug flag is set', () => {
flags_mock.isDebug = true;
printer.debug(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"this is a test line"`);
});

it('does not print debug lines by default', () => {
Expand All @@ -43,18 +35,12 @@ it('does not print debug lines by default', () => {

it('prints info line by default', () => {
printer.info(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"this is a test line"`);
});

it('prints info line in specified color', () => {
printer.info(testInput, 'blue');
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"this is a test line"`);
});

it('does not print info line when silent flag is set', () => {
Expand All @@ -65,10 +51,7 @@ it('does not print info line when silent flag is set', () => {

it('prints success line by default', () => {
printer.success(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"✅ this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"✅ this is a test line"`);
});

it('does not print success line when silent flag is set', () => {
Expand All @@ -79,34 +62,22 @@ it('does not print success line when silent flag is set', () => {

it('prints warn line by default', () => {
printer.warn(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"⚠️ this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"⚠️ this is a test line"`);
});

it('prints warn line when silent flag is set', () => {
flags_mock.isSilent = true;
printer.warn(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"⚠️ this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"⚠️ this is a test line"`);
});

it('prints error line by default', () => {
printer.error(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"🛑 this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"🛑 this is a test line"`);
});

it('prints error line when silent flag is set', () => {
flags_mock.isSilent = true;
printer.error(testInput);
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(`
"🛑 this is a test line
"
`);
expect(writeStream_stub.write.mock.calls[0][0].trim()).toMatchInlineSnapshot(`"🛑 this is a test line"`);
});