Sha256: 208418a3bfaa3d1fad2b2e6128fa7b2ff65bc885350608446acb49de4ea7d58f

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

const path = require("path");
const {
  app_javascript,
  node_modules,
  node_modules_included,
  createTestCompiler,
  createTrackLoader,
} = require("./__utils__/webpack");
const swcConfig = require("../swc");

jest.mock("../../config", () => {
  const original = jest.requireActual("../../config");
  return {
    ...original,
    webpack_loader: "swc",
    additional_paths: [...original.additional_paths, "node_modules/included"],
  };
});

const createWebpackConfig = (file, use) => {
  return {
    entry: { file },
    module: {
      rules: [
        {
          ...swcConfig,
          use,
        },
      ],
    },
    output: {
      path: "/",
      filename: "scripts-bundled.js",
    },
  };
};

describe("swc", () => {
  test("process source path", async () => {
    const normalPath = `${app_javascript}/a.js`;
    const [tracked, loader] = createTrackLoader();
    const compiler = createTestCompiler(
      createWebpackConfig(normalPath, loader)
    );
    await compiler.run();
    expect(tracked[normalPath]).toBeTruthy();
  });

  test("exclude node_modules", async () => {
    const ignored = `${node_modules}/a.js`;
    const [tracked, loader] = createTrackLoader();
    const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
    await compiler.run();
    expect(tracked[ignored]).toBeUndefined();
  });

  test("explicitly included node_modules should be transpiled", async () => {
    const included = `${node_modules_included}/a.js`;
    const [tracked, loader] = createTrackLoader();
    const compiler = createTestCompiler(createWebpackConfig(included, loader));
    await compiler.run();
    expect(tracked[included]).toBeTruthy();
  });
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shakapacker-6.6.0 package/rules/__tests__/swc.js
shakapacker-6.5.6 package/rules/__tests__/swc.js