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

fix: notBundle test is failed #247

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

think-flow
Copy link
Contributor

环境:windows 11
node版本:v20.10.0
当我运行notBundle测试时会出现以下错误

 FAIL  test/plugin.test.ts > src/plugin > notBundle
AssertionError: expected '"use strict";\r\nvar __create = Objec…' to equal '"use strict";\nvar __create = Object.…'

- Expected
+ Received

- "use strict";
- var __create = Object.create;
- var __defProp = Object.defineProperty;
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
- var __getOwnPropNames = Object.getOwnPropertyNames;
- var __getProtoOf = Object.getPrototypeOf;
- var __hasOwnProp = Object.prototype.hasOwnProperty;
- var __copyProps = (to, from, except, desc) => {
-   if (from && typeof from === "object" || typeof from === "function") {
-     for (let key of __getOwnPropNames(from))
-       if (!__hasOwnProp.call(to, key) && key !== except)
-         __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
-   }
-   return to;
- };
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
-   // If the importer is in node compatibility mode or this is not an ESM
-   // file that has been converted to a CommonJS file using a Babel-
-   // compatible transform (i.e. "__esModule" has not been set), then set
-   // "default" to the CommonJS "module.exports" for node compatibility.
-   isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
-   mod
- ));
- const vite = require("vite");
- const message = "foo";
- console.log(import("vite"));
- console.log(vite);
- console.log(message);
+ "use strict";
+ var __create = Object.create;
+ var __defProp = Object.defineProperty;
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
+ var __getOwnPropNames = Object.getOwnPropertyNames;
+ var __getProtoOf = Object.getPrototypeOf;
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
+ var __copyProps = (to, from, except, desc) => {
+   if (from && typeof from === "object" || typeof from === "function") {
+     for (let key of __getOwnPropNames(from))
+       if (!__hasOwnProp.call(to, key) && key !== except)
+         __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
+   }
+   return to;
+ };
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
+   // If the importer is in node compatibility mode or this is not an ESM
+   // file that has been converted to a CommonJS file using a Babel-
+   // compatible transform (i.e. "__esModule" has not been set), then set
+   // "default" to the CommonJS "module.exports" for node compatibility.
+   isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
+   mod
+ ));
+ const vite = require("vite");
+ const message = "foo";
+ console.log(import("vite"));
+ console.log(vite);
+ console.log(message);


 ❯ test/plugin.test.ts:36:22
     34|     const normalSnapMain = snapMain.replace(normalizingNewLineRE, '\n')
     35|
     36|     expect(distMain).equal(snapMain)
       |                      ^
     37|   })
     38| })

经检查是因为两个文件的换行符不一致。
__snapshots__/external-main.js\r\n,而生成出来的dis/external-main.js\n
我个人认为,两个文件的差异只有不可见的换行符时,可以通过标准化换行符后进行测试,而不影响该测试原来的目的

Copy link
Contributor

@yejimeiming yejimeiming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@caoxiemeihao caoxiemeihao merged commit 149c4a9 into electron-vite:main Sep 18, 2024
@yejimeiming yejimeiming mentioned this pull request Sep 19, 2024
@iugo
Copy link

iugo commented Oct 1, 2024

历史原因 Windows 下一般使用 CRLF, 但是 Linux, macOS 这样的类 UNIX 一般使用 LF (古早版本的 macOS 使用 CR 的情况现在已经罕见).

@think-flow

我打开 https://github.com/electron-vite/vite-plugin-electron/blob/4aae5577faa39928d3ab6af35bde827a91c29be9/test/__snapshots__/external-main.js 看了一下, 应该是 LF 的.

所以怀疑您是否转过结构, 导致您本地 __snapshots__/external-main.js 文件是 CRLF?

@think-flow
Copy link
Contributor Author

历史原因 Windows 下一般使用 CRLF, 但是 Linux, macOS 这样的类 UNIX 一般使用 LF (古早版本的 macOS 使用 CR 的情况现在已经罕见).

@think-flow

我打开 https://github.com/electron-vite/vite-plugin-electron/blob/4aae5577faa39928d3ab6af35bde827a91c29be9/test/__snapshots__/external-main.js 看了一下, 应该是 LF 的.

所以怀疑您是否转过结构, 导致您本地 __snapshots__/external-main.js 文件是 CRLF?

感谢您的指正,我的本地__snapshots__/external-main.js确实是CRLF。
经过排查,是因为我使用的windows版git没有配置core.autocrlf,导致git将我拉取的代码由LF转换为了CRLF。
我会谨记这次疏漏。
再次感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants