-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
856 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Webpack plugin > should handle a JSON schema with a reference 1`] = `"(()=>{"use strict";console.log({openapi:"3.0.0",info:{title:"My great API",description:"Great description",version:"1.0.0"},paths:{"/my/path":{get:{summary:"Some GET request",responses:{200:{description:"Some response",content:{"application/json":{schema:{type:"object",properties:{someKey:{type:"string"}},required:["someKey"]},example:{someKey:"some value"}}}}}}}}})})();"`; | ||
|
||
exports[`Webpack plugin > should handle a YAML schema with a reference 1`] = `"(()=>{"use strict";console.log({openapi:"3.0.0",info:{title:"My great API",description:"Great description",version:"1.0.0"},paths:{"/my/path":{get:{summary:"Some GET request",responses:{200:{description:"Some response",content:{"application/json":{schema:{type:"object",properties:{someKey:{type:"string"}},required:["someKey"]},example:{someKey:"some value"}}}}}}}}})})();"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import api from "../api.openapi.json"; | ||
|
||
console.log(api); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import api from "../api.yaml"; | ||
|
||
console.log(api); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { unplugin } from "./index.js"; | ||
|
||
export default unplugin.webpack as typeof unplugin.webpack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Volume, createFsFromVolume } from "memfs"; | ||
import { describe, expect, it } from "vitest"; | ||
import webpack, { type OutputFileSystem } from "webpack"; | ||
import webpackPlugin from "./webpack.js"; | ||
|
||
async function build(config: webpack.Configuration): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const compiler = webpack({ | ||
mode: "production", | ||
output: { | ||
path: "/", // Set to '/' since we are using an in-memory filesystem | ||
filename: "bundle.js", // Output file name | ||
}, | ||
...config, | ||
}); | ||
const vol = new Volume(); | ||
const memFs = createFsFromVolume(vol); | ||
compiler.outputFileSystem = memFs as OutputFileSystem; | ||
|
||
compiler.run((err, stats) => { | ||
if (err || stats?.hasErrors()) { | ||
reject(err || stats?.toJson().errors); | ||
return; | ||
} | ||
|
||
const transformedCode = memFs.readFileSync("/bundle.js", "utf-8"); | ||
|
||
resolve(transformedCode.toString()); | ||
}); | ||
}); | ||
} | ||
|
||
describe("Webpack plugin", () => { | ||
it("should handle a YAML schema with a reference", async () => { | ||
const code = await build({ | ||
entry: "./src/fixtures/webpack/main.js", | ||
plugins: [webpackPlugin()], | ||
}); | ||
|
||
expect(code).toMatchSnapshot(); | ||
expect(code).toContain('type:"object",'); | ||
}); | ||
|
||
it("should handle a JSON schema with a reference", async () => { | ||
const code = await build({ | ||
entry: "./src/fixtures/webpack/main-json.js", | ||
plugins: [ | ||
webpackPlugin({ | ||
extensions: [".openapi.json"], | ||
}), | ||
], | ||
}); | ||
|
||
expect(code).toMatchSnapshot(); | ||
expect(code).toContain('type:"object",'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters