|
1 | 1 | import { Logger, Options, ParameterType } from "../../../lib/utils"; |
2 | 2 | import { |
| 3 | + BindOption, |
3 | 4 | MapDeclarationOption, |
4 | 5 | NumberDeclarationOption, |
5 | 6 | } from "../../../lib/utils/options"; |
@@ -108,4 +109,56 @@ describe("Options", () => { |
108 | 109 |
|
109 | 110 | throws(() => options.isSet("does not exist" as never)); |
110 | 111 | }); |
| 112 | + |
| 113 | + it("Throws if sealed and a value is set", () => { |
| 114 | + const options = new Options(new Logger()); |
| 115 | + options.addDefaultDeclarations(); |
| 116 | + options.seal(); |
| 117 | + |
| 118 | + throws(() => options.setValue("emit", true)); |
| 119 | + throws(() => options.setCompilerOptions([], {}, [])); |
| 120 | + }); |
| 121 | +}); |
| 122 | + |
| 123 | +describe("BindOption", () => { |
| 124 | + class Container { |
| 125 | + constructor(public options: Options) {} |
| 126 | + |
| 127 | + @BindOption("emit") |
| 128 | + emit!: boolean; |
| 129 | + } |
| 130 | + |
| 131 | + it("Supports fetching options", () => { |
| 132 | + const options = new Options(new Logger()); |
| 133 | + options.addDefaultDeclarations(); |
| 134 | + |
| 135 | + const container = new Container(options); |
| 136 | + equal(container.emit, false); |
| 137 | + }); |
| 138 | + |
| 139 | + it("Updates as option values change", () => { |
| 140 | + const options = new Options(new Logger()); |
| 141 | + options.addDefaultDeclarations(); |
| 142 | + |
| 143 | + const container = new Container(options); |
| 144 | + equal(container.emit, false); |
| 145 | + |
| 146 | + options.setValue("emit", true); |
| 147 | + equal(container.emit, true); |
| 148 | + }); |
| 149 | + |
| 150 | + it("Caches set options when sealed", () => { |
| 151 | + const options = new Options(new Logger()); |
| 152 | + options.addDefaultDeclarations(); |
| 153 | + |
| 154 | + const container = new Container(options); |
| 155 | + |
| 156 | + options.setValue("emit", true); |
| 157 | + options.seal(); |
| 158 | + equal(container.emit, true); |
| 159 | + |
| 160 | + const prop = Object.getOwnPropertyDescriptor(container, "emit")!; |
| 161 | + equal(prop.get, void 0); |
| 162 | + equal(prop.value, true); |
| 163 | + }); |
111 | 164 | }); |
0 commit comments