Files
test-repo/tests_integration/__tests__/parser-api.js
T
Danny McCormick 18b03a31cc Fix tests for Windows and add Azure Pipelines for cross platform CI (#5410)
* Add azure pipelines

* Add gitattributes

* Updating tests to work on Windows or Unix

* Lint

* Cleaning up

* Fixing names

* Clean up naming

* try to consolidate images

* Clean up

* Add back txt to gitattributes
2018-11-14 07:55:50 -05:00

43 lines
997 B
JavaScript

"use strict";
const prettier = require("prettier/local");
const runPrettier = require("../runPrettier");
test("allows custom parser provided as object", () => {
const output = prettier.format("1", {
parser(text) {
expect(text).toEqual("1");
return {
type: "Literal",
value: 2,
raw: "2"
};
}
});
expect(output).toEqual("2");
});
test("allows usage of prettier's supported parsers", () => {
const output = prettier.format("foo ( )", {
parser(text, parsers) {
expect(typeof parsers.babylon).toEqual("function");
const ast = parsers.babylon(text);
ast.program.body[0].expression.callee.name = "bar";
return ast;
}
});
expect(output).toEqual("bar();\n");
});
describe("allows passing a string to resolve a parser", () => {
runPrettier("./custom-parsers/", [
"--end-of-line",
"lf",
"./custom-rename-input.js",
"--parser",
"./custom-rename-parser"
]).test({
status: 0
});
});