Skip to content

Commit 39b40e4

Browse files
authored
test(wtr): windows compat, kinda (#5578)
* chore(ci): use GitHub Actions for cross-platform tests, not SuaceLabs Don't delete SauceLabs tho (yet) * chore: not a template string * test(integration): disable flaky tests (temporarily) * chore(integration-tests): remove leading `test-` from filenames It's implicit in the files being in the test directory and long filenames cause problems on windows * chore(integration-tests): `delegate-focus-` -> `delegates-focus-` * chore(integration-tests): rename `tab-index-` to `tabindex-` * chore(integration-tests): remove `-elements` * chore(integration-tests): rename `previous-` to `prev-` * test(integration-tests): await async method * chore(integration-tests): fully remove `test-` prefix * test(integration-tests): derive test names instead of hard-coding easier to maintain and uncovered a few broken tests! * chore(integration-tests): rename way-too-long test name * chore(ci): attempt to run bash on windows and everywhere * chore(ci): declare env vars in more cross-platform manner * chore(ci): run yarn install in bash * chore(ci): give up and use cross-env * chore(ci): try without `exec` * test(wtr): change variable name is SAUCE defined in CI? * chore(ci): remove saucelabs * test(ci): run unit tests on windows * chore(ci): why different? * chore(ci): avoid unnecessasry rebuild * chore(ci): windows compat * Revert "chore(ci): windows compat" This reverts commit e4279e3. * chore(ci): windows compat * chore(ci): update actions versions * chore(ci): install chromedriver as part of setup-chrome * chore(ci): more sloppy windows compat * chore(ci): more windowsy * chore: add package manager * chore(ci): more windowsy * chore(ci): more windowsy * chore(ci): more windowsy * chore(ci): crlf smh * chore(ci): revert setup-chrome@v2 * chore: include call stack * chore: debug * chore: actually, nvm don't need to change this file for this task * test(wtr): jsdoc for the doc gods * chore(ci): update input descriptions * chore: revert unrelated changes * chore: more windowsy * chore: revert unrelated changes * test(wtr): disable tests broken on windows * revert: just log text * chore(ci): remove unnecessary env var * chore(ci): add names for clarity * chore: move `x` to `c` maybe makes windows work * chore: update usage of `x` to `c` maybe makes windows work * chore: update usage of `X-` to `C-` maybe makes windows work * test(wtr): fix scope tokens * test(wtr): order can be different * test(wtr): try to normalize filenames * chore: update yarn.lock * test(wtr): enable browser logs * test(wtr): filter out [WDIO] logs * test(wtr): try to fix windows * test(wtr): no browser logs they're mostly noise * test(wtr): test objects in matrix * Revert "test(wtr): test objects in matrix" This reverts commit 4f1181c. * chore(ci): split jobs to make faster, maybe * chore(ci): fail-fast: false * chore(ci): merge jobs * chore(ci): merge more jobs * chore(ci): reconfigure so it hopefully works * chore(ci): consolidate hydration tests * chore(ci): exclude engine-server flag + SSR v2 runtime combo * chore(ci): add default env hydration tests * chore(ci): use correct SSR package for hydration tests * chore(ci): give up on windows * chore(ci): give up on windows * Revert "chore: move `x` to `c`" This reverts commit 6f32328. * test(wtr): revert usage of `c` to `x` * Apply suggestion from @wjhsf * test(wtr): revert `c-` to `x-` * test(wtr): revert scope tokens * test(wtr): re-enable tests that only fail on windows * chore(ci): revert CI changes * chore: restore saucelabs dep
1 parent 8972e65 commit 39b40e4

File tree

11 files changed

+54
-38
lines changed

11 files changed

+54
-38
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"printWidth": 100,
33
"singleQuote": true,
44
"tabWidth": 4,
5-
"trailingComma": "es5"
5+
"trailingComma": "es5",
6+
"endOfLine": "lf"
67
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@
108108
"http-cache-semantics": "4.2.0",
109109
"@types/estree": "^1.0.8"
110110
},
111-
"dependencies": {}
111+
"dependencies": {},
112+
"packageManager": "yarn@1.22.22"
112113
}

packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const LWC_SSR = readFileSync(
1212
'utf8'
1313
);
1414

15-
const ROOT_DIR = path.join(import.meta.dirname, '../..');
15+
const ROOT_DIR = path.join(import.meta.dirname, '..', '..');
1616
const COMPONENT_NAME = 'x-main';
1717
const COMPONENT_ENTRYPOINT = 'x/main/main.js';
1818

@@ -25,7 +25,9 @@ async function compileModule(input, targetSSR, format) {
2525
targetSSR,
2626
modules: [{ dir: modulesDir }],
2727
experimentalDynamicComponent: {
28-
loader: fileURLToPath(new URL('../../helpers/loader.js', import.meta.url)),
28+
loader: fileURLToPath(
29+
new URL('../../helpers/loader.js', import.meta.url)
30+
).replaceAll(path.sep, path.posix.sep),
2931
strict: true,
3032
},
3133
enableSyntheticElementInternals: true,
@@ -108,8 +110,8 @@ async function getSsrMarkup(componentEntrypoint, configPath) {
108110
* This function wraps those configs in the test code to be executed.
109111
*/
110112
async function wrapHydrationTest(configPath) {
111-
const suiteDir = path.dirname(configPath);
112-
const componentEntrypoint = path.join(suiteDir, COMPONENT_ENTRYPOINT);
113+
const suiteDir = path.posix.dirname(configPath);
114+
const componentEntrypoint = path.posix.join(suiteDir, COMPONENT_ENTRYPOINT);
113115
const ssrOutput = await getSsrMarkup(componentEntrypoint, configPath);
114116

115117
return `

packages/@lwc/integration-not-karma/configs/plugins/test-hydration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { spyOn } from '@vitest/spy';
22
import * as LWC from 'lwc';
33
import { setHooks } from '../../helpers/hooks';
4+
import { resetDOM, resetAlreadyLoggedMessages } from '../../helpers/reset';
45

56
/*
67
* Because these tests are written in JS, the type defs below are not enforced. They are provided
@@ -132,6 +133,9 @@ export function runTest(configPath, componentPath, ssrRendered) {
132133

133134
afterEach(() => {
134135
consoleSpy.reset();
136+
// in case of retries
137+
resetDOM();
138+
resetAlreadyLoggedMessages();
135139
});
136140

137141
afterAll(() => {

packages/@lwc/rollup-plugin/src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export interface RollupLwcOptions {
7979

8080
const PLUGIN_NAME = 'rollup-plugin-lwc-compiler';
8181

82-
const IMPLICIT_DEFAULT_HTML_PATH = '@lwc/resources/empty_html.js';
82+
const IMPLICIT_DEFAULT_HTML_PATH = ['@lwc', 'resources', 'empty_html.js'].join(path.sep);
8383
const EMPTY_IMPLICIT_HTML_CONTENT = 'export default void 0';
84-
const IMPLICIT_DEFAULT_CSS_PATH = '@lwc/resources/empty_css.css';
84+
const IMPLICIT_DEFAULT_CSS_PATH = ['@lwc', 'resources', 'empty_css.css'].join(path.sep);
8585
const EMPTY_IMPLICIT_CSS_CONTENT = '';
8686
const SCRIPT_FILE_EXTENSIONS = ['.js', '.mjs', '.jsx', '.ts', '.mts', '.tsx'];
8787

@@ -352,18 +352,19 @@ export default function lwc(pluginOptions: RollupLwcOptions = {}): Plugin {
352352
// Specifier will only exist for modules with alias paths.
353353
// Otherwise, use the file directory structure to resolve namespace and name.
354354
const [namespace, name] =
355-
// Note we do not need to use path.sep here because this filename contains
356-
// a '/' regardless of Windows vs Unix, since it comes from the Rollup `id`
357-
specifier?.split('/') ?? path.dirname(filename).split('/').slice(-2);
355+
specifier?.split('/') ?? path.dirname(filename).split(path.sep).slice(-2);
358356

359357
/* v8 ignore next */
360358
if (!namespace || !name) {
361359
// TODO [#4824]: Make this an error rather than a warning
362360
this.warn(
363-
'The component namespace and name could not be determined from the specifier ' +
364-
JSON.stringify(specifier) +
365-
' or filename ' +
366-
JSON.stringify(filename)
361+
`The component namespace and name (${JSON.stringify(
362+
namespace
363+
)} and ${JSON.stringify(
364+
name
365+
)}) could not be determined from the specifier ${JSON.stringify(
366+
specifier
367+
)} or filename ${JSON.stringify(path.dirname(filename))}`
367368
);
368369
}
369370

playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"description": "Playground project to experiment with LWC.",
77
"scripts": {
88
"dev": "rollup -c --watch",
9-
"build": "NODE_ENV=production rollup -c"
9+
"build": "cross-env NODE_ENV=production rollup -c"
1010
},
1111
"devDependencies": {
1212
"@lwc/rollup-plugin": "8.24.0",
1313
"@rollup/plugin-replace": "^6.0.3",
1414
"@rollup/plugin-typescript": "^12.3.0",
15+
"cross-env": "^10.1.0",
1516
"lwc": "8.24.0",
1617
"rollup": "^4.52.5",
1718
"rollup-plugin-livereload": "^2.0.5",

scripts/tasks/check-and-rewrite-package-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const expectedPkgJsons = [];
4040

4141
for (const dir of globSync('./packages/@lwc/*')) {
4242
const filename = path.join('./', dir, 'package.json');
43-
const actual = fs.readFileSync(filename, 'utf-8');
43+
const actual = fs.readFileSync(filename, 'utf-8').replace(/\r\n/g, '\n'); // Windows compat
4444
const pkg = JSON.parse(actual);
4545
// Skip private packages
4646
if (pkg.private) {

scripts/tasks/generate-license-files.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ const formattedLicense = await prettier.format(newLicense, {
9898

9999
// Check against current top-level license for changes
100100
const shouldWarnChanges =
101-
process.argv.includes('--test') && formattedLicense !== (await readFile('LICENSE.md', 'utf-8'));
101+
process.argv.includes('--test') &&
102+
formattedLicense !== (await readFile('LICENSE.md', 'utf-8')).replace(/\r\n/g, '\n');
102103

103104
// Top level license
104105
await writeFile('LICENSE.md', formattedLicense, 'utf-8');

scripts/tasks/verify-treeshakable.mjs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
*/
77

88
// Inspired from: https://github.com/Rich-Harris/agadoo
9-
import path from 'node:path';
109
import { rollup } from 'rollup';
1110
import pluginVirtual from '../rollup/plugin-virtual.mjs';
1211

1312
async function check(input) {
14-
const resolved = path.resolve(input);
15-
1613
// Tell rollup to bundle a fake file whose content is just `import "path from CLI arg"`
1714
// If the imported file is tree-shakeable (pure imports/exports, no side effects),
1815
// then the bundled code will be an empty file
1916
const bundle = await rollup({
2017
input: '__virtual__',
21-
plugins: [pluginVirtual(`import "${resolved}";`)],
18+
plugins: [pluginVirtual(`import "${input}";`)],
2219
onwarn: (warning, handle) => {
2320
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
2421
},
@@ -28,26 +25,20 @@ async function check(input) {
2825
format: 'esm',
2926
});
3027

31-
const [chunk] = res.output;
28+
const [{ code }] = res.output;
3229

3330
return {
34-
code: chunk.code,
35-
isTreeShakable: chunk.code.trim().length === 0,
31+
code,
32+
isTreeShakable: code.trim().length === 0,
3633
};
3734
}
3835

3936
const input = process.argv[2];
40-
check(input)
41-
.then((res) => {
42-
if (res.isTreeShakable === false) {
43-
console.error(
44-
`${res.code}\n❗️ Failed to fully treeshake ${input}; see remaining code above.`
45-
);
46-
}
37+
const result = await check(input);
38+
if (!result.isTreeShakable) {
39+
console.error(
40+
`${result.code}\n❗️ Failed to fully treeshake ${input}; see remaining code above.`
41+
);
42+
}
4743

48-
process.exit(res.isTreeShakable ? 0 : 1);
49-
})
50-
.catch((err) => {
51-
console.error(err);
52-
process.exit(1);
53-
});
44+
process.exitCode = result.isTreeShakable ? 0 : 1;

0 commit comments

Comments
 (0)