| 1 |
import fs from "fs"; |
| 2 |
import path from "path"; |
| 3 |
import { parseSync } from "../lib/index.js"; |
| 4 |
import { fileURLToPath } from "url"; |
| 5 |
import { createRequire } from "module"; |
| 6 |
|
| 7 |
const require = createRequire(import.meta.url); |
| 8 |
|
| 9 |
function fixture(...args) { |
| 10 |
return path.join( |
| 11 |
path.dirname(fileURLToPath(import.meta.url)), |
| 12 |
"fixtures", |
| 13 |
"parse", |
| 14 |
...args, |
| 15 |
); |
| 16 |
} |
| 17 |
|
| 18 |
describe("parseSync", function () { |
| 19 |
it("should parse using configuration from .babelrc when a filename is provided", function () { |
| 20 |
const input = fs.readFileSync(fixture("input.js"), "utf8"); |
| 21 |
const output = require(fixture("output")); |
| 22 |
|
| 23 |
const result = parseSync(input, { |
| 24 |
filename: fixture("input.js"), |
| 25 |
cwd: fixture(), |
| 26 |
}); |
| 27 |
expect(JSON.parse(JSON.stringify(result))).toEqual(output); |
| 28 |
}); |
| 29 |
|
| 30 |
it("should parse using passed in configuration", function () { |
| 31 |
const input = fs.readFileSync(fixture("input.js"), "utf8"); |
| 32 |
const output = require(fixture("output.json")); |
| 33 |
|
| 34 |
const result = parseSync(input, { |
| 35 |
parserOpts: { |
| 36 |
plugins: [["decorators", { decoratorsBeforeExport: false }]], |
| 37 |
}, |
| 38 |
cwd: fixture(), |
| 39 |
}); |
| 40 |
expect(JSON.parse(JSON.stringify(result))).toEqual(output); |
| 41 |
}); |
| 42 |
}); |