Implement last opened functionality (#4633)
* Implement last opened functionality Fixes https://github.com/cdr/code-server/issues/4619 * Fix test temp dirs not being cleaned up * Mock logger everywhere This suppresses all the error and debug output we generate which makes it hard to actually find which test has failed. It also gives us a standard way to test logging for the few places we do that. * Use separate data directories for unit test instances Exactly as we do for the e2e tests. * Add integration tests for vscode route * Make settings use --user-data-dir Without this test instances step on each other feet and they also clobber your own non-test settings. * Make redirects consistent They will preserve the trailing slash if there is one. * Remove compilation check If you do a regular non-watch build there are no compilation stats so this bricks VS Code in CI when running the unit tests. I am not sure how best to fix this for the case where you have a build that has not been packaged yet so I just removed it for now and added a message to check if VS Code is compiling when in dev mode. * Update code-server update endpoint name
This commit is contained in:
@ -361,13 +361,11 @@ describe("parser", () => {
|
||||
})
|
||||
|
||||
describe("cli", () => {
|
||||
let testDir: string
|
||||
const testName = "cli"
|
||||
const vscodeIpcPath = path.join(os.tmpdir(), "vscode-ipc")
|
||||
|
||||
beforeAll(async () => {
|
||||
testDir = await tmpdir("cli")
|
||||
await fs.rmdir(testDir, { recursive: true })
|
||||
await fs.mkdir(testDir, { recursive: true })
|
||||
await clean(testName)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -416,6 +414,7 @@ describe("cli", () => {
|
||||
args._ = ["./file"]
|
||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
||||
|
||||
const testDir = await tmpdir(testName)
|
||||
const socketPath = path.join(testDir, "socket")
|
||||
await fs.writeFile(vscodeIpcPath, socketPath)
|
||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
||||
@ -635,14 +634,15 @@ describe("readSocketPath", () => {
|
||||
let tmpDirPath: string
|
||||
let tmpFilePath: string
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDirPath = await tmpdir("readSocketPath")
|
||||
tmpFilePath = path.join(tmpDirPath, "readSocketPath.txt")
|
||||
await fs.writeFile(tmpFilePath, fileContents)
|
||||
const testName = "readSocketPath"
|
||||
beforeAll(async () => {
|
||||
await clean(testName)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await fs.rmdir(tmpDirPath, { recursive: true })
|
||||
beforeEach(async () => {
|
||||
tmpDirPath = await tmpdir(testName)
|
||||
tmpFilePath = path.join(tmpDirPath, "readSocketPath.txt")
|
||||
await fs.writeFile(tmpFilePath, fileContents)
|
||||
})
|
||||
|
||||
it("should throw an error if it can't read the file", async () => {
|
||||
@ -677,9 +677,10 @@ describe("toVsCodeArgs", () => {
|
||||
version: false,
|
||||
}
|
||||
|
||||
const testName = "vscode-args"
|
||||
beforeAll(async () => {
|
||||
// Clean up temporary directories from the previous run.
|
||||
await clean("vscode-args")
|
||||
await clean(testName)
|
||||
})
|
||||
|
||||
it("should convert empty args", async () => {
|
||||
@ -691,7 +692,7 @@ describe("toVsCodeArgs", () => {
|
||||
})
|
||||
|
||||
it("should convert with workspace", async () => {
|
||||
const workspace = path.join(await tmpdir("vscode-args"), "test.code-workspace")
|
||||
const workspace = path.join(await tmpdir(testName), "test.code-workspace")
|
||||
await fs.writeFile(workspace, "foobar")
|
||||
expect(await toVsCodeArgs(await setDefaults(parse([workspace])))).toStrictEqual({
|
||||
...vscodeDefaults,
|
||||
@ -702,7 +703,7 @@ describe("toVsCodeArgs", () => {
|
||||
})
|
||||
|
||||
it("should convert with folder", async () => {
|
||||
const folder = await tmpdir("vscode-args")
|
||||
const folder = await tmpdir(testName)
|
||||
expect(await toVsCodeArgs(await setDefaults(parse([folder])))).toStrictEqual({
|
||||
...vscodeDefaults,
|
||||
folder,
|
||||
@ -712,7 +713,7 @@ describe("toVsCodeArgs", () => {
|
||||
})
|
||||
|
||||
it("should ignore regular file", async () => {
|
||||
const file = path.join(await tmpdir("vscode-args"), "file")
|
||||
const file = path.join(await tmpdir(testName), "file")
|
||||
await fs.writeFile(file, "foobar")
|
||||
expect(await toVsCodeArgs(await setDefaults(parse([file])))).toStrictEqual({
|
||||
...vscodeDefaults,
|
||||
|
Reference in New Issue
Block a user