Skip to content

Commit

Permalink
update: used babel-plugin-tester instead of bare jest instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
WanQuanXie committed Aug 15, 2024
1 parent eebc1cd commit 116c578
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 56 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/fixtures/default-import/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
throws: true,
};
3 changes: 3 additions & 0 deletions src/__tests__/fixtures/mix-default-specifier-usage/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
throws: true,
};
File renamed without changes.
3 changes: 3 additions & 0 deletions src/__tests__/fixtures/unknown-icon/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
throws: true,
};
62 changes: 6 additions & 56 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,10 @@
import path from "node:path";
import fs from "node:fs";
import { transformFileSync } from "@babel/core";
import { pluginTester } from "babel-plugin-tester";
import plugin from "../index";
import { LUCIDE_REACT_NATIVE } from "../const";

describe("lucide-react-native modularized builds", () => {
const fixturesDir = path.join(__dirname, "fixtures");
const errorFixturesDir = path.join(__dirname, "fixtures", "error");

fs.readdirSync(fixturesDir)
.filter((caseName) => caseName !== "error")
.map((caseName) => {
const fixtureDir = path.join(fixturesDir, caseName);
const actualFile = path.join(fixtureDir, "actual.js");
const expectedFile = path.join(fixtureDir, "expected.js");

describe(`should work with ${caseName.split("-").join(" ")}`, () => {
// Programmatically test with the useES option both on and off
it("cjs", () => {
const actual = transformFileSync(actualFile, {
compact: true,
plugins: [plugin],
})?.code?.trim();
const expected = transformFileSync(expectedFile, {
compact: true,
})?.code?.trim();
expect(actual).toBe(expected);
});

it("esm", () => {
const actual = transformFileSync(actualFile, {
compact: true,
plugins: [[plugin, { useES: true }]],
})?.code;

// The only difference is that cjs should be replaced with esm. This way, no changes to
// the tests are needed to cover testing of useES.
const expected = transformFileSync(expectedFile, {
compact: true,
})?.code?.replace(/cjs/g, "esm");
expect(actual).toBe(expected);
});
});
});

fs.readdirSync(errorFixturesDir).map((caseName) => {
const fixtureDir = path.join(fixturesDir, caseName);
const actualFile = path.join(fixtureDir, "actual.js");

describe(`should throw an error with ${caseName.split("-").join(" ")}`, () => {
it(`${caseName.split("-").join(" ")}`, () => {
expect(function () {
transformFileSync(actualFile, {
plugins: [plugin],
})?.code;
}).toThrow();
});
});
});
pluginTester({
plugin,
pluginName: LUCIDE_REACT_NATIVE,
fixtures: path.join(__dirname, "fixtures"),
});

0 comments on commit 116c578

Please sign in to comment.