|
1 | 1 | import * as path from "path"; |
2 | 2 | import * as util from "../../util"; |
| 3 | +import { Plugin } from "../../../src/transpilation/plugins"; |
3 | 4 | import * as ts from "typescript"; |
4 | 5 |
|
5 | 6 | test("printer", () => { |
@@ -182,3 +183,61 @@ test("afterEmit plugin", () => { |
182 | 183 | expect(diagnostic?.category).toBe(ts.DiagnosticCategory.Message); |
183 | 184 | expect(diagnostic?.messageText).toContain("After emit"); |
184 | 185 | }); |
| 186 | + |
| 187 | +test("in memory plugin", () => { |
| 188 | + const { diagnostics } = util.testModule`` |
| 189 | + .setOptions({ |
| 190 | + luaPlugins: [ |
| 191 | + { |
| 192 | + plugin: { |
| 193 | + afterEmit(program: ts.Program) { |
| 194 | + return [ |
| 195 | + { |
| 196 | + category: ts.DiagnosticCategory.Message, |
| 197 | + messageText: "In memory plugin diagnostic message!", |
| 198 | + code: 1234, |
| 199 | + file: program.getSourceFiles()[0], |
| 200 | + start: undefined, |
| 201 | + length: undefined, |
| 202 | + } satisfies ts.Diagnostic, |
| 203 | + ]; |
| 204 | + }, |
| 205 | + } satisfies Plugin, |
| 206 | + }, |
| 207 | + ], |
| 208 | + }) |
| 209 | + .getLuaResult(); |
| 210 | + |
| 211 | + expect(diagnostics).toHaveLength(1); |
| 212 | + expect(diagnostics[0].code).toBe(1234); |
| 213 | +}); |
| 214 | + |
| 215 | +test("in memory plugin with factory", () => { |
| 216 | + const { diagnostics } = util.testModule`` |
| 217 | + .setOptions({ |
| 218 | + luaPlugins: [ |
| 219 | + { |
| 220 | + code: 1234, |
| 221 | + plugin: options => |
| 222 | + ({ |
| 223 | + afterEmit(program: ts.Program) { |
| 224 | + return [ |
| 225 | + { |
| 226 | + category: ts.DiagnosticCategory.Message, |
| 227 | + messageText: "In memory plugin diagnostic message!", |
| 228 | + code: options.code, |
| 229 | + file: program.getSourceFiles()[0], |
| 230 | + start: undefined, |
| 231 | + length: undefined, |
| 232 | + } satisfies ts.Diagnostic, |
| 233 | + ]; |
| 234 | + }, |
| 235 | + } satisfies Plugin), |
| 236 | + }, |
| 237 | + ], |
| 238 | + }) |
| 239 | + .getLuaResult(); |
| 240 | + |
| 241 | + expect(diagnostics).toHaveLength(1); |
| 242 | + expect(diagnostics[0].code).toBe(1234); |
| 243 | +}); |
0 commit comments