[test] Add test for Logger
Sathya Gunasekaran committed
Nov 28, 2023 at 15:35 UTC
e53e944580d4972f97d392de1470697c7a661019
1 file changed
+36
compiler/packages/babel-plugin-react-forget/src/__tests__/Logger-test.ts
new
+36
@@ -0,0 +1,36 @@
1
+/**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+import invariant from "invariant";
9
+import { runReactForgetBabelPlugin } from "../Babel/RunReactForgetBabelPlugin";
10
+import type { Logger, LoggerEvent } from "../Entrypoint";
11
+
12
+it("logs succesful compilation", () => {
13
+ const logs: [string | null, LoggerEvent][] = [];
14
+ const logger: Logger = {
15
+ logEvent(filename, event) {
16
+ logs.push([filename, event]);
17
+ },
18
+ };
19
+
20
+ const _ = runReactForgetBabelPlugin(
21
+ "function Component(props) { return <div>{props}</div> }",
22
+ "test.js",
23
+ "flow",
24
+ { logger, panicThreshold: "ALL_ERRORS" } as any
25
+ );
26
+
27
+ const [filename, event] = logs.at(0)!;
28
+ expect(filename).toContain("test.js");
29
+ expect(event.kind).toEqual("CompileSuccess");
30
+ invariant(event.kind === "CompileSuccess", "typescript be smarter");
31
+ expect(event.fnName).toEqual("Component");
32
+ expect(event.fnLoc).toEqual({
33
+ end: { column: 55, line: 1 },
34
+ start: { column: 0, line: 1 },
35
+ });
36
+});