Files
test-repo/tests/integration/__tests__/bundle.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
JavaScript
Raw Normal View History

import path from "node:path";
import createEsmUtils from "esm-utils";
import { projectRoot } from "../env.js";
import coreOptions from "../../../src/main/core-options.js";
import codeSamples from "../../../website/playground/codeSamples.mjs";
import jestPathSerializer from "../path-serializer.js";
2022-02-05 16:24:10 +03:00
const fastGlob = require("fast-glob");
2020-09-17 01:08:44 +09:00
const { require } = createEsmUtils(import.meta);
expect.addSnapshotSerializer(jestPathSerializer);
2020-09-17 01:08:44 +09:00
const parserNames = coreOptions.options.parser.choices.map(
({ value }) => value
);
const distDirectory = path.join(projectRoot, "dist");
let esmStandalone;
let esmPlugins;
beforeAll(async () => {
({ default: esmStandalone } = await import(
path.join(distDirectory, "esm/standalone.mjs")
));
esmPlugins = await Promise.all(
2022-02-09 09:22:32 +08:00
fastGlob
.sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true })
.map(async (file) => (await import(file)).default)
);
});
2020-09-17 01:08:44 +09:00
describe("standalone", () => {
const standalone = require(path.join(distDirectory, "standalone.js"));
2022-02-05 16:24:10 +03:00
const plugins = fastGlob
2020-09-17 01:08:44 +09:00
.sync(["parser-*.js"], { cwd: distDirectory, absolute: true })
.map((file) => require(file));
for (const parser of parserNames) {
test(parser, () => {
const input = codeSamples(parser);
const umdOutput = standalone.format(input, {
parser,
plugins,
});
expect(typeof input).toBe("string");
expect(typeof umdOutput).toBe("string");
expect(umdOutput).not.toBe(input);
const esmOutput = esmStandalone.format(input, {
parser,
plugins: esmPlugins,
});
expect(esmOutput).toBe(umdOutput);
});
}
});