2021-06-06 17:09:53 -07:00
|
|
|
/**
|
|
|
|
* Copyright Microsoft Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
|
|
|
|
2021-09-27 18:58:08 +02:00
|
|
|
test('should get top level stdio', async ({ runInlineTest }) => {
|
2021-06-06 17:09:53 -07:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.spec.js': `
|
2023-02-14 19:20:56 -08:00
|
|
|
import { test, expect } from '@playwright/test';
|
2021-06-06 17:09:53 -07:00
|
|
|
console.log('\\n%% top level stdout');
|
|
|
|
console.error('\\n%% top level stderr');
|
|
|
|
test('is a test', () => {
|
|
|
|
console.log('\\n%% stdout in a test');
|
|
|
|
console.error('\\n%% stderr in a test');
|
|
|
|
});
|
|
|
|
`
|
|
|
|
});
|
2021-08-04 21:11:02 -07:00
|
|
|
// top level logs appear twice, because the file is required twice
|
2023-02-07 15:11:44 -08:00
|
|
|
expect(result.outputLines.sort()).toEqual([
|
|
|
|
'stderr in a test',
|
|
|
|
'stdout in a test',
|
|
|
|
'top level stderr',
|
|
|
|
'top level stderr',
|
|
|
|
'top level stdout',
|
|
|
|
'top level stdout',
|
2021-06-06 17:09:53 -07:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-12-15 10:39:49 -08:00
|
|
|
test('should get stdio from worker fixture teardown', async ({ runInlineTest }) => {
|
2021-06-06 17:09:53 -07:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'helper.ts': `
|
2023-02-14 19:20:56 -08:00
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
export const test = base.extend({
|
2021-06-06 17:09:53 -07:00
|
|
|
fixture: [ async ({}, run) => {
|
|
|
|
console.log('\\n%% worker setup');
|
|
|
|
await run();
|
|
|
|
console.log('\\n%% worker teardown');
|
|
|
|
}, { scope: 'worker' } ]
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'a.spec.js': `
|
|
|
|
const { test } = require('./helper');
|
|
|
|
test('is a test', async ({fixture}) => {});
|
|
|
|
`
|
|
|
|
});
|
2023-02-07 15:11:44 -08:00
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
'worker setup',
|
|
|
|
'worker teardown'
|
2021-06-06 17:09:53 -07:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-09-27 18:58:08 +02:00
|
|
|
test('should ignore stdio when quiet', async ({ runInlineTest }) => {
|
2021-08-19 18:20:53 -07:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { quiet: true };
|
|
|
|
`,
|
|
|
|
'a.spec.js': `
|
2023-02-14 19:20:56 -08:00
|
|
|
import { test, expect } from '@playwright/test';
|
2021-08-19 18:20:53 -07:00
|
|
|
test('is a test', () => {
|
|
|
|
console.log('\\n%% stdout in a test');
|
|
|
|
console.error('\\n%% stderr in a test');
|
|
|
|
});
|
|
|
|
`
|
2022-02-24 12:39:28 -08:00
|
|
|
}, { reporter: 'list' });
|
2021-08-19 18:20:53 -07:00
|
|
|
expect(result.output).not.toContain('%%');
|
|
|
|
});
|
2022-07-07 17:56:41 -07:00
|
|
|
|
2024-03-25 15:31:58 -07:00
|
|
|
test('should support console colors but not tty', {
|
|
|
|
annotation: [
|
|
|
|
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15366' },
|
|
|
|
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29839' },
|
|
|
|
],
|
|
|
|
}, async ({ runInlineTest, nodeVersion }) => {
|
|
|
|
test.skip(nodeVersion.major < 18, 'Node16 does not respect FORCE_COLOR in onsole');
|
|
|
|
|
2022-07-07 17:56:41 -07:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.spec.js': `
|
2023-02-14 19:20:56 -08:00
|
|
|
import { test, expect } from '@playwright/test';
|
2022-07-07 17:56:41 -07:00
|
|
|
test('console log', () => {
|
|
|
|
console.log('process.stdout.isTTY = ' + process.stdout.isTTY);
|
|
|
|
console.log('process.stderr.isTTY = ' + process.stderr.isTTY);
|
|
|
|
console.log({ b: true, n: 123, s: 'abc' });
|
|
|
|
console.error({ b: false, n: 123, s: 'abc' });
|
|
|
|
});
|
|
|
|
`
|
|
|
|
});
|
2024-03-25 15:31:58 -07:00
|
|
|
expect(result.output).toContain(`process.stdout.isTTY = undefined`);
|
|
|
|
expect(result.output).toContain(`process.stderr.isTTY = undefined`);
|
2022-07-07 17:56:41 -07:00
|
|
|
// The output should have colors.
|
2023-02-07 15:11:44 -08:00
|
|
|
expect(result.rawOutput).toContain(`{ b: \x1b[33mtrue\x1b[39m, n: \x1b[33m123\x1b[39m, s: \x1b[32m'abc'\x1b[39m }`);
|
|
|
|
expect(result.rawOutput).toContain(`{ b: \x1b[33mfalse\x1b[39m, n: \x1b[33m123\x1b[39m, s: \x1b[32m'abc'\x1b[39m }`);
|
2022-07-07 17:56:41 -07:00
|
|
|
});
|
2022-07-12 14:47:14 -07:00
|
|
|
|
|
|
|
test('should not throw type error when using assert', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.spec.js': `
|
2023-02-14 19:20:56 -08:00
|
|
|
import { test, expect } from '@playwright/test';
|
2022-07-12 14:47:14 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
test('assert no type error', () => {
|
|
|
|
assert.strictEqual(1, 2);
|
|
|
|
});
|
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(result.output).not.toContain(`TypeError: process.stderr.hasColors is not a function`);
|
|
|
|
expect(result.output).toContain(`AssertionError`);
|
|
|
|
});
|