Completed
This commit is contained in:
@ -1,34 +1,53 @@
|
||||
import { describe, it } from "mocha";
|
||||
import { expect } from "chai";
|
||||
import { transform } from "@babel/core";
|
||||
import { format } from "prettier";
|
||||
import plugin from "../src/index";
|
||||
import { readFileSync } from "fs"
|
||||
import { describe, it } from "mocha"
|
||||
import { resolve } from "path"
|
||||
import { expect } from "chai"
|
||||
import { transform } from "@babel/core"
|
||||
import { format } from "prettier"
|
||||
import type { Snapshot } from "./snapshots"
|
||||
import plugin from "../src/index"
|
||||
|
||||
const javascript = (code: TemplateStringsArray) =>
|
||||
transform(code[0], {
|
||||
const canonize = (code: string) =>
|
||||
format(code, { parser: "babel" }).trim().split("\n").filter(Boolean).join("\n")
|
||||
|
||||
const equal = (name: Snapshot) => {
|
||||
const folder = resolve(__dirname, "snapshots", name)
|
||||
const actual = readFileSync(resolve(folder, "input.txt"), "utf-8")
|
||||
const expected = readFileSync(resolve(folder, "output.txt"), "utf-8")
|
||||
const transformed = transform(actual, {
|
||||
parserOpts: {
|
||||
plugins: ["decorators-legacy", "typescript"],
|
||||
},
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
plugins: [plugin],
|
||||
})!.code!;
|
||||
})!.code!
|
||||
expect(canonize(transformed)).to.deep.equal(canonize(expected))
|
||||
}
|
||||
|
||||
const canonize = (code: string) => format(code, { parser: "babel" }).trim();
|
||||
describe("tsc-decorator", () => {
|
||||
it("works with property decorators", () => {
|
||||
equal("properties")
|
||||
})
|
||||
|
||||
const equal = (actual: string, expected: string) => {
|
||||
actual = canonize(actual);
|
||||
expected = canonize(expected);
|
||||
expect(actual).to.deep.equal(expected);
|
||||
};
|
||||
it("works with method decorators", () => {
|
||||
equal("methods")
|
||||
})
|
||||
|
||||
describe("", () => {
|
||||
it("should do nothing", () => {
|
||||
equal(
|
||||
javascript`
|
||||
class A {}
|
||||
`,
|
||||
/* javascript */ `
|
||||
class A {}
|
||||
`
|
||||
);
|
||||
});
|
||||
});
|
||||
it("works with parameter decorators", () => {
|
||||
equal("params")
|
||||
})
|
||||
|
||||
// https://github.com/babel/babel/issues/13591
|
||||
it.skip("works with computed property keys", () => {
|
||||
equal("computedProperties")
|
||||
})
|
||||
|
||||
it("works with class/consrtuctor decorators", () => {
|
||||
equal("constructor")
|
||||
})
|
||||
|
||||
it("does not interfere with export declarations", () => {
|
||||
equal("exports")
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user