Files
test-repo/tests/integration/__tests__/bundle.js
T
fisker Cheung f0b63f3dff Merge branch 'main' into next
# Conflicts:
#	CONTRIBUTING.md
#	cspell.json
#	docs/options.md
#	package.json
#	scripts/build/bundler.mjs
#	src/language-css/loc.js
#	src/language-css/parser-postcss.js
#	src/language-css/utils/index.js
#	tests/format/js/arrows-bind/jsfmt.spec.js
#	tests/format/js/async-do-expressions/jsfmt.spec.js
#	tests/format/js/bind-expressions/jsfmt.spec.js
#	tests/format/js/classes/top-level-super/jsfmt.spec.js
#	tests/format/js/comments-pipeline-own-line/jsfmt.spec.js
#	tests/format/js/decorator-comments/jsfmt.spec.js
#	tests/format/js/decorators-export/jsfmt.spec.js
#	tests/format/js/decorators/jsfmt.spec.js
#	tests/format/js/do/jsfmt.spec.js
#	tests/format/js/export-default/escaped/jsfmt.spec.js
#	tests/format/js/export-extension/jsfmt.spec.js
#	tests/format/js/export-star/jsfmt.spec.js
#	tests/format/js/exports/jsfmt.spec.js
#	tests/format/js/invalid-code/jsfmt.spec.js
#	tests/format/js/logical-assignment/jsfmt.spec.js
#	tests/format/js/multiparser-invalid/jsfmt.spec.js
#	tests/format/js/no-semi-babylon-extensions/jsfmt.spec.js
#	tests/format/js/object-property-comment/jsfmt.spec.js
#	tests/format/js/partial-application/jsfmt.spec.js
#	tests/format/js/pipeline-operator/jsfmt.spec.js
#	tests/format/js/private-in/jsfmt.spec.js
#	tests/format/js/record/jsfmt.spec.js
#	tests/format/js/reserved-word/jsfmt.spec.js
#	tests/format/js/strings/jsfmt.spec.js
#	tests/format/js/throw_expressions/jsfmt.spec.js
#	tests/format/js/trailing-whitespace/jsfmt.spec.js
#	tests/format/js/v8_intrinsic/jsfmt.spec.js
#	tests/format/misc/errors/js/literal/jsfmt.spec.js
#	tests/format/misc/errors/js/object/jsfmt.spec.js
#	tests/format/misc/errors/js/variable-declarator/jsfmt.spec.js
#	tests/integration/__tests__/bundle.js
#	tsconfig.json
#	yarn.lock
2022-02-09 09:22:32 +08:00

58 lines
1.6 KiB
JavaScript

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";
const fastGlob = require("fast-glob");
const { require } = createEsmUtils(import.meta);
expect.addSnapshotSerializer(jestPathSerializer);
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(
fastGlob
.sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true })
.map(async (file) => (await import(file)).default)
);
});
describe("standalone", () => {
const standalone = require(path.join(distDirectory, "standalone.js"));
const plugins = fastGlob
.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);
});
}
});