|
| 1 | +const assert = require("assert"); |
| 2 | +const { existsSync, writeFileSync } = require("fs"); |
| 3 | +const { join } = require("path"); |
| 4 | +const vscode = require("vscode"); |
| 5 | + |
| 6 | +const projectPath1 = join(workspaceDir, "project-1"); |
| 7 | +/** @type {Project} */ |
| 8 | +let project; |
| 9 | +/** @type {Device} */ |
| 10 | +let device; |
| 11 | + |
| 12 | +const readUntil = (string) => new Promise((resolve) => device.readUntil(string, resolve)); |
| 13 | + |
| 14 | +beforeAll(async () => { |
| 15 | + // Create a project and add a device |
| 16 | + // todo should createProject resolve promise only once project is added to projectsStore? |
| 17 | + await pymakr.commands.createProject(vscode.Uri.parse(projectPath1), { |
| 18 | + name: "my project", |
| 19 | + dev: { simulateDeepSleep: true }, |
| 20 | + }); |
| 21 | + await new Promise((resolve) => pymakr.projectsStore.next(resolve)); |
| 22 | + project = pymakr.projectsStore.get()[0]; |
| 23 | + device = pymakr.devicesStore.get()[0]; |
| 24 | + project.setDevices([device]); |
| 25 | + assert(existsSync(projectPath1)); |
| 26 | + assert.equal(project.name, "my project"); |
| 27 | + assert(device); |
| 28 | +}); |
| 29 | + |
| 30 | +test("can fake deepsleep in devmode", async () => { |
| 31 | + test("can put project in dev mode", async () => { |
| 32 | + await device.connect(); |
| 33 | + // await pymakr.commands.eraseDevice({ device }, "empty"); |
| 34 | + // device.onTerminalData((data) => console.log("data", data)); |
| 35 | + await pymakr.commands.startDevMode({ project }); |
| 36 | + assert(project.watcher.active); |
| 37 | + assert.equal(project.watcher.deviceManagers.length, 1); |
| 38 | + }); |
| 39 | + test("first save in devmode install devtools and restarts", async () => { |
| 40 | + writeFileSync(projectPath1 + "/main.py", 'print("hello world")'); |
| 41 | + await readUntil("uploading Pymakr devtools"); |
| 42 | + await readUntil("patching boot.dev"); |
| 43 | + await readUntil("changed. Restarting..."); |
| 44 | + await readUntil(">>>"); |
| 45 | + await readUntil(">>>"); |
| 46 | + console.log("after reset"); |
| 47 | + |
| 48 | + test("sys.path includes _pymakr_dev", async () => { |
| 49 | + console.log("before sys check"); |
| 50 | + const result = await device.runScript("import sys\nprint(sys.path)"); |
| 51 | + assert(result.match(/\/_pymakr_dev/), "did not find _pymakr_dev. Found: " + result.toString()); |
| 52 | + }); |
| 53 | + |
| 54 | + test("pymakr_dev/fake_machine.py exists on device", async () => { |
| 55 | + const result = await device.runScript("print(os.listdir('_pymakr_dev'))"); |
| 56 | + assert(result.match("fake_machine.py")); |
| 57 | + }); |
| 58 | + |
| 59 | + test("can import fake_machine in devmode", async () => { |
| 60 | + const result = await device.runScript("import fake_machine\nfake_machine.sleep(1)"); |
| 61 | + console.log("result", result); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments