-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests to ensure ignored files are ignored by the child process as…
… well
- Loading branch information
Showing
12 changed files
with
156 additions
and
17 deletions.
There are no files selected for viewing
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
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 @@ | ||
export const foo = "foo"; |
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 @@ | ||
export function success() { | ||
return !!(1 + 1); | ||
} |
File renamed without changes.
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ module.exports = { | |
"type": "commonjs", | ||
"strictMode": false | ||
} | ||
} | ||
}, | ||
ignore: ["ignored.ts"] | ||
} |
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 |
---|---|---|
|
@@ -13,5 +13,5 @@ module.exports = { | |
"strictMode": true, | ||
"lazy": true | ||
} | ||
} | ||
}, | ||
} |
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,90 @@ | ||
import assert from "assert"; | ||
import type { ChildProcess } from "child_process"; | ||
import http from "http"; | ||
import path from "path"; | ||
import { Supervisor } from "../src/Supervisor"; | ||
import { wds } from "../src/index"; | ||
|
||
describe("wds", () => { | ||
let cwd: any; | ||
let supervisorRestart: any; | ||
let socketPath: string; | ||
|
||
const sendCompileRequest = async (filename: string) => { | ||
assert(socketPath, "socketPath must be set"); | ||
const result = await new Promise((resolve, reject) => { | ||
const request = http.request({ socketPath, path: "/compile", method: "POST", timeout: 200 }, (resp) => { | ||
let data = ""; | ||
if (resp.statusCode !== 200) { | ||
return reject(`Error compiling`); | ||
} | ||
resp.on("data", (chunk: string) => (data += chunk)); | ||
resp.on("end", () => resolve(JSON.parse(data).filenames)); | ||
}); | ||
|
||
request.on("error", (error) => { | ||
reject(error); | ||
}); | ||
request.write(filename); | ||
request.end(); | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
beforeEach(() => { | ||
cwd = jest.spyOn(process, "cwd").mockImplementation(() => { | ||
return path.resolve(__dirname, "fixtures/src/files_with_config"); | ||
}); | ||
|
||
supervisorRestart = jest.spyOn(Supervisor.prototype, "restart").mockImplementation(function () { | ||
const self = this as unknown as Supervisor; | ||
socketPath = self.socketPath; | ||
self.process = { | ||
on: jest.fn(), | ||
} as unknown as ChildProcess; | ||
return self.process; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cwd.mockRestore(); | ||
supervisorRestart.mockRestore(); | ||
}); | ||
|
||
test("server responds to ignored files", async () => { | ||
const server = await wds({ | ||
argv: [], | ||
terminalCommands: false, | ||
reloadOnChanges: false, | ||
}); | ||
const result = (await sendCompileRequest(path.resolve(__dirname, "fixtures/src/files_with_config/ignored.ts"))) as Record< | ||
string, | ||
string | { ignored: boolean } | ||
>; | ||
const compiledKeys = Object.keys(result).filter((k) => /spec\/fixtures\/src\/files_with_config\/ignored\.ts/.test(k)); | ||
expect(compiledKeys).toHaveLength(1); | ||
expect(result[compiledKeys[0]]).toEqual({ | ||
ignored: true, | ||
}); | ||
|
||
server.close(); | ||
}); | ||
|
||
test("server responds to included files", async () => { | ||
const server = await wds({ | ||
argv: [], | ||
terminalCommands: false, | ||
reloadOnChanges: false, | ||
}); | ||
const result = (await sendCompileRequest(path.resolve(__dirname, "fixtures/src/files_with_config/simple.ts"))) as Record< | ||
string, | ||
string | { ignored: boolean } | ||
>; | ||
const compiledKeys = Object.keys(result).filter((k) => /spec\/fixtures\/src\/files_with_config\/simple\.ts/.test(k)); | ||
expect(compiledKeys).toHaveLength(1); | ||
expect(typeof result[compiledKeys[0]]).toBe("string"); | ||
|
||
server.close(); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -22,6 +22,6 @@ | |
"node_modules/@types/jest/index.d.ts" | ||
], | ||
"exclude": [ | ||
"spec/fixtures", | ||
"spec/fixtures" | ||
] | ||
} |