Skip to content

Commit

Permalink
Use esm imports in tests (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandernanberg authored Dec 22, 2024
1 parent e12e430 commit 8a26072
Show file tree
Hide file tree
Showing 21 changed files with 623 additions and 615 deletions.
18 changes: 9 additions & 9 deletions packages/babel-plugin-fbtee-runtime/src/__tests__/index-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fbtee from '@nkzw/babel-plugin-fbtee';
import fbtAutoImport from '@nkzw/babel-plugin-fbtee-auto-import';
import {
assertSourceAstEqual,
withFbtRequireStatement,
withFbtImportStatement,
} from '@nkzw/babel-plugin-fbtee/src/__tests__/FbtTestUtil.tsx';
import fbteeRuntime from '../index.tsx';

Expand All @@ -23,10 +23,10 @@ const runTest = (data: { input: string; output: string }) =>
describe('Test hash key generation', () => {
it('should generate hash key for simply string', () => {
const data = {
input: withFbtRequireStatement(`
input: withFbtImportStatement(`
fbt('Foo', 'Bar');
`),
output: withFbtRequireStatement(`
output: withFbtImportStatement(`
fbt._('Foo', null, {hk: '3ktBJ2'});
`),
};
Expand All @@ -35,7 +35,7 @@ describe('Test hash key generation', () => {

it('should generate hash key for nested fbts', () => {
const data = {
input: withFbtRequireStatement(
input: withFbtImportStatement(
`<fbt desc="d">
<fbt:param
name="two
Expand All @@ -47,7 +47,7 @@ lines">
test
</fbt>;`,
),
output: withFbtRequireStatement(
output: withFbtImportStatement(
`fbt._(
'{two lines} test',
[
Expand Down Expand Up @@ -117,10 +117,10 @@ lines">
describe('Test enum hash keys generation', () => {
it('should generate single hash key for fbt with enum under regular mode', () => {
runTest({
input: withFbtRequireStatement(
input: withFbtImportStatement(
`fbt('Foo ' + fbt.enum('a', {a: 'A', b: 'B', c: 'C'}), 'Bar');`,
),
output: withFbtRequireStatement(
output: withFbtImportStatement(
`fbt._(
{
"a": "Foo A",
Expand All @@ -143,7 +143,7 @@ describe('Test enum hash keys generation', () => {

test('Test replacing clear token names with mangled tokens', () => {
const data = {
input: withFbtRequireStatement(
input: withFbtImportStatement(
`<fbt desc="d">
<b>Your</b>
friends
Expand All @@ -157,7 +157,7 @@ test('Test replacing clear token names with mangled tokens', () => {
</fbt>;`,
),
output: `var fbt_sv_arg_0;
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt_sv_arg_0 = fbt._plural(ex1.count, "number"),
fbt._(
{
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-plugin-fbtee/src/__tests__/FbtTestUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export const snapshotTransformKeepJsx = (
): Promise<string> =>
transformKeepJsx(source, { fbtBase64: true, ...pluginOptions });

export function withFbsRequireStatement(code: string): string {
return `const { fbs } = require("fbtee");
export function withFbsImportStatement(code: string): string {
return `import { fbs } from "fbtee";
${code}`;
}

export function withFbtRequireStatement(code: string): string {
return `const { fbt } = require("fbtee");
export function withFbtImportStatement(code: string): string {
return `import { fbt } from "fbtee";
${code}`;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test declarative (jsx) <fbs> syntax translation should convert a common string 1`] = `
const { fbs } = require("fbtee");
import { fbs } from "fbtee";
const fbsCommonElem = fbs._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "Button to post a comment", text: "Post" } },
Expand All @@ -12,7 +12,7 @@ const fbsCommonElem = fbs._(
`;
exports[`Test declarative (jsx) <fbs> syntax translation should convert a simple string 1`] = `
const { fbs } = require("fbtee");
import { fbs } from "fbtee";
const fbsElem = fbs._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "str_description", text: "a simple string" } },
Expand All @@ -23,7 +23,7 @@ const fbsElem = fbs._(
`;
exports[`Test declarative (jsx) <fbs> syntax translation should convert a string with a parameter 1`] = `
const { fbs } = require("fbtee");
import { fbs } from "fbtee";
const fbsElem = fbs._(
/* __FBT__ start */ {
jsfbt: {
Expand All @@ -38,8 +38,8 @@ const fbsElem = fbs._(
`;
exports[`Test declarative (jsx) <fbs> syntax translation should handle <fbs:enum> 1`] = `
const { fbs } = require("fbtee");
let aEnum = require("Test$FbtEnum");
import { fbs } from "fbtee";
import aEnum from "Test$FbtEnum";
var x = fbs._(
/* __FBT__ start */ {
jsfbt: {
Expand All @@ -58,7 +58,7 @@ var x = fbs._(
`;
exports[`Test functional fbs() syntax translation should convert a common string 1`] = `
const { fbs } = require("fbtee");
import { fbs } from "fbtee";
const fbsCommonCall = fbs._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "Button to post a comment", text: "Post" } },
Expand All @@ -69,7 +69,7 @@ const fbsCommonCall = fbs._(
`;
exports[`Test functional fbs() syntax translation should convert a simple string 1`] = `
const { fbs } = require("fbtee");
import { fbs } from "fbtee";
const fbsCall = fbs._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "str_description", text: "a simple string" } },
Expand All @@ -80,8 +80,8 @@ const fbsCall = fbs._(
`;
exports[`Test functional fbs() syntax translation should convert a string with a gender parameter 1`] = `
const { fbs } = require("fbtee");
const IntlVariations = require("IntlVariations");
import { fbs } from "fbtee";
import IntlVariations from "IntlVariations";
const fbsCall = fbs._(
/* __FBT__ start */ {
jsfbt: {
Expand All @@ -98,8 +98,8 @@ const fbsCall = fbs._(
`;
exports[`Test functional fbs() syntax translation should handle fbs.enum 1`] = `
const { fbs } = require("fbtee");
let aEnum = require("Test$FbtEnum");
import { fbs } from "fbtee";
import aEnum from "Test$FbtEnum";
var x = fbs._(
/* __FBT__ start */ {
jsfbt: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test double-lined params should remove the new line for param names that are two lines 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "d", text: "{two lines} test" } },
Expand Down Expand Up @@ -60,7 +60,7 @@ fbt._(
`;

exports[`fbt() API: using FBT subject should accept "subject" as a parameter 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand All @@ -75,7 +75,7 @@ fbt._(
`;

exports[`fbt() API: using FBT subject with string templates should accept "subject" as a parameter 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand All @@ -90,7 +90,7 @@ fbt._(
`;

exports[`fragments inside of <fbt:param> 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "d", text: "{param} test" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Test jsx auto-wrapping of implicit parameters can handle multiple variations in nested strings 1`] = `
var fbt_sv_arg_0, fbt_sv_arg_1;
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
(fbt_sv_arg_0 = fbt._name("bar", bar, g)),
(fbt_sv_arg_1 = fbt._plural(num, "baz")),
fbt._(
Expand Down Expand Up @@ -107,7 +107,7 @@ const { fbt } = require("fbtee");

exports[`Test jsx auto-wrapping of implicit parameters can handle multiple variations in nested strings and a subject gender 1`] = `
var fbt_sv_arg_0, fbt_sv_arg_1, fbt_sv_arg_2;
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
(fbt_sv_arg_0 = fbt._subject(g0)),
(fbt_sv_arg_1 = fbt._pronoun(1, g1)),
(fbt_sv_arg_2 = fbt._plural(num, "foo")),
Expand Down Expand Up @@ -301,7 +301,7 @@ const { fbt } = require("fbtee");

exports[`Test jsx auto-wrapping of implicit parameters can handle multiple variations in nested strings with substrings that look identical 1`] = `
var fbt_sv_arg_0, fbt_sv_arg_1, fbt_sv_arg_2;
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
(fbt_sv_arg_0 = fbt._subject(g0)),
(fbt_sv_arg_1 = fbt._pronoun(1, g1)),
(fbt_sv_arg_2 = fbt._pronoun(1, g2)),
Expand Down Expand Up @@ -607,7 +607,7 @@ const { fbt } = require("fbtee");
`;

exports[`Test jsx auto-wrapping of implicit parameters should auto wrap a simple test with a nested level 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -670,7 +670,7 @@ fbt._(
`;

exports[`Test jsx auto-wrapping of implicit parameters should auto wrap a simple test with one level 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -711,7 +711,7 @@ fbt._(
`;

exports[`Test jsx auto-wrapping of implicit parameters should work with multiple <fbt> calls in one file 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
/*#__PURE__*/ React.createElement(
"div",
null,
Expand Down Expand Up @@ -789,7 +789,7 @@ const { fbt } = require("fbtee");
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap a <fbt> child nested in an explicit <fbt:param> 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: { m: [], t: { desc: "d", text: "{explicit fbt param}" } },
Expand Down Expand Up @@ -843,7 +843,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap a <fbt> child next to an explicit <fbt:param> 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -895,7 +895,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap a single unwrapped <fbt> child and a string above 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -958,7 +958,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap a single unwrapped <fbt> child and a string below 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -999,7 +999,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap a string next to an explicit <fbt:param> that has a implicit <fbt:param> within it 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1059,7 +1059,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap an outer and inner child 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1124,7 +1124,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap explicit params nested in implicit params with [] 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1291,7 +1291,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap two children with one nested level 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1380,7 +1380,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap two nested next to each other 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1490,7 +1490,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap two nested next to each other with an extra level 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1624,7 +1624,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap two unwrapped <fbt> children 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down Expand Up @@ -1682,7 +1682,7 @@ fbt._(
`;
exports[`Test jsx auto-wrapping of implicit parameters should wrap two unwrapped <fbt> children and 1 nested 1`] = `
const { fbt } = require("fbtee");
import { fbt } from "fbtee";
fbt._(
/* __FBT__ start */ {
jsfbt: {
Expand Down
Loading

0 comments on commit 8a26072

Please sign in to comment.