playwright/packages/installation-tests/esm-playwright-test.mjs
Joel Einbinder 7caf05b24a
fix(playwright-test): have the proper default export (#7328)
There are 3 ways to import `@playwright/test` library in the modern Node.js ecosystem:
- Using `require`: works great, this patch doesn't change it
- Using `import` statement from `.mjs` file - we have wrong `default` for @playwright/test that should be a `test`. This is what test checks for
- Using `import test from '@playwright/test'` from `.ts` file - was broken because TypeScript thought it's a CJS module, whereas it's a ESM module in reality.

Also, typescript types import from `.d.ts` file was broken because we had no default export (`export *` syntax does not export default).
2021-06-25 15:29:22 -07:00

25 lines
1.0 KiB
JavaScript

/**
* 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 { chromium, firefox, webkit, selectors, devices, errors, test } from '@playwright/test';
import * as playwright from '@playwright/test';
import defaultExport from '@playwright/test';
import errorsFile from '@playwright/test/lib/utils/errors.js';
import testESM from './esm.mjs';
if (defaultExport !== test)
process.exit(1);
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium, firefox, webkit]);