54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
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 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!
|
|
expect(canonize(transformed)).to.deep.equal(canonize(expected))
|
|
}
|
|
|
|
describe("tsc-decorator", () => {
|
|
it("works with property decorators", () => {
|
|
equal("properties")
|
|
})
|
|
|
|
it("works with method decorators", () => {
|
|
equal("methods")
|
|
})
|
|
|
|
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")
|
|
})
|
|
})
|