From 4b22c3f003ca2a54cd8af6823e516b7bca169d38 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 26 Sep 2022 17:53:08 -0800 Subject: [PATCH] chery-pick(#17599): Revert "fix(pwt): compatibility in CWD with wrong casing (#16636)" --- packages/playwright-test/src/loader.ts | 22 ---------- tests/installation/npmTest.ts | 4 +- ...should-handle-incorrect-cwd-casing.spec.ts | 41 ------------------- tests/installation/playwright.config.ts | 2 +- 4 files changed, 3 insertions(+), 66 deletions(-) delete mode 100644 tests/installation/playwright-test-should-handle-incorrect-cwd-casing.spec.ts diff --git a/packages/playwright-test/src/loader.ts b/packages/playwright-test/src/loader.ts index 7beb4dcedf1e8..40b03e092e04f 100644 --- a/packages/playwright-test/src/loader.ts +++ b/packages/playwright-test/src/loader.ts @@ -295,8 +295,6 @@ export class Loader { } private async _requireOrImport(file: string) { - if (process.platform === 'win32') - file = await fixWin32FilepathCapitalization(file); const revertBabelRequire = installTransform(); const isModule = fileIsModule(file); try { @@ -688,23 +686,3 @@ export function folderIsModule(folder: string): boolean { // Rely on `require` internal caching logic. return require(packageJsonPath).type === 'module'; } - -async function fixWin32FilepathCapitalization(file: string): Promise { - /** - * On Windows with PowerShell <= 6 it is possible to have a CWD with different - * casing than what the actual directory on the filesystem is. This can cause - * that we require the file multiple times with different casing. To mitigate - * this we get the actual underlying filesystem path and use that. - * https://github.com/microsoft/playwright/issues/9193#issuecomment-1219362150 - */ - const realFile = await new Promise((resolve, reject) => fs.realpath.native(file, (error, realFile) => { - if (error) - return reject(error); - resolve(realFile); - })); - // We do not want to resolve them (e.g. 8.3 filenames), so we do a best effort - // approach by only using it if the actual lowercase characters are the same: - if (realFile.toLowerCase() === file.toLowerCase()) - return realFile; - return file; -} diff --git a/tests/installation/npmTest.ts b/tests/installation/npmTest.ts index 7e086c1071c0f..86e8a9eeaa093 100644 --- a/tests/installation/npmTest.ts +++ b/tests/installation/npmTest.ts @@ -25,8 +25,8 @@ import debugLogger from 'debug'; import { Registry } from './registry'; import { spawnAsync } from './spawnAsync'; -// os.tmpdir() on Windows returns a 8.3 filename, so we resolve it. -export const TMP_WORKSPACES = path.join(os.platform() === 'darwin' ? '/tmp' : fs.realpathSync.native(os.tmpdir()), 'pwt', 'workspaces'); + +export const TMP_WORKSPACES = path.join(os.platform() === 'darwin' ? '/tmp' : os.tmpdir(), 'pwt', 'workspaces'); const debug = debugLogger('itest'); diff --git a/tests/installation/playwright-test-should-handle-incorrect-cwd-casing.spec.ts b/tests/installation/playwright-test-should-handle-incorrect-cwd-casing.spec.ts deleted file mode 100644 index 6099097191b4a..0000000000000 --- a/tests/installation/playwright-test-should-handle-incorrect-cwd-casing.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * - * 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 fs from 'fs'; -import path from 'path'; -import { test, expect } from './npmTest'; - -test('@playwright/test should handle incorrect cwd casing', async ({ exec, tmpWorkspace }) => { - test.skip(process.platform !== 'win32'); - const cwd = path.join(tmpWorkspace, 'expectedcasing'); - fs.mkdirSync(cwd); - fs.writeFileSync(path.join(cwd, 'sample.spec.ts'), ` - import { test, expect } from '@playwright/test'; - test('should pass', async () => { - expect(1 + 1).toBe(2); - }) - `); - fs.writeFileSync(path.join(cwd, 'sample.spec.js'), ` - const { test, expect } = require('@playwright/test'); - test('should pass', async () => { - expect(1 + 1).toBe(2); - }) - `); - await exec('npm init -y', { cwd }); - await exec('npm i --foreground-scripts @playwright/test', { cwd }); - - const output = await exec('npx playwright test --reporter=list', { cwd: path.join(tmpWorkspace, 'eXpEcTeDcAsInG') }); - expect(output).toContain('2 passed'); -}); diff --git a/tests/installation/playwright.config.ts b/tests/installation/playwright.config.ts index c0f553e44ba7f..712fa633dc228 100644 --- a/tests/installation/playwright.config.ts +++ b/tests/installation/playwright.config.ts @@ -27,7 +27,7 @@ const config: PlaywrightTestConfig = { timeout: 5 * 60 * 1000, retries: 0, reporter: process.env.CI ? [ - ['list'], + ['dot'], ['json', { outputFile: path.join(outputDir, 'report.json') }], ] : [['list'], ['html', { open: 'on-failure' }]], forbidOnly: !!process.env.CI,