plugin-options.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { parse } from "../lib";
  2. function getParser(code, plugins) {
  3. return () => parse(code, { plugins, sourceType: "module" });
  4. }
  5. describe("plugin options", function() {
  6. describe("the first options are used", function() {
  7. // NOTE: This test is not specific about decorators, it can be applied
  8. // to any plugin with options.
  9. const NAME = "decorators";
  10. const OPT_1 = [NAME, { decoratorsBeforeExport: true }];
  11. const OPT_2 = [NAME, { decoratorsBeforeExport: false }];
  12. const SYNTAX_1 = "@dec export class C {}";
  13. const SYNTAX_2 = "export @dec class C {}";
  14. const SYNTAX_DEFAULT = "export @dec class C {}";
  15. it("when they aren't specified", function() {
  16. expect(getParser(SYNTAX_DEFAULT, [NAME, OPT_1])).not.toThrow();
  17. expect(getParser(SYNTAX_DEFAULT, [NAME, OPT_2])).not.toThrow();
  18. });
  19. it("when they are specified", function() {
  20. expect(getParser(SYNTAX_1, [OPT_1, OPT_2])).not.toThrow();
  21. expect(getParser(SYNTAX_2, [OPT_2, OPT_1])).not.toThrow();
  22. expect(getParser(SYNTAX_1, [OPT_2, OPT_1])).toThrow();
  23. expect(getParser(SYNTAX_2, [OPT_1, OPT_2])).toThrow();
  24. });
  25. });
  26. });