-
Couldn't load subscription status.
- Fork 27
Adding Truffle Exec context menu #73
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| // Copyright (c) Consensys Software Inc. All rights reserved. | ||
| // Licensed under the MIT license. | ||
| import {Uri} from "vscode"; | ||
|
|
||
| export interface IExtensionAdapter { | ||
| validateExtension: () => Promise<void>; | ||
| build: (...args: Array<string>) => Promise<void>; | ||
| deploy: () => Promise<void>; | ||
|
|
||
| execScript: (uri: Uri) => Promise<void>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) Consensys Software Inc. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import assert from "assert"; | ||
| import {SinonMock, SinonExpectation, SinonStub, mock, stub, restore} from "sinon"; | ||
| import uuid from "uuid"; | ||
| import {CancellationToken, Progress, ProgressOptions, window, Uri} from "vscode"; | ||
| import {TruffleCommands} from "../../src/commands/TruffleCommands"; | ||
| import * as helpers from "../../src/helpers"; | ||
| import * as commands from "../../src/helpers/command"; | ||
| import {TestConstants} from "../TestConstants"; | ||
| import {join} from "path"; | ||
|
|
||
| describe("ExecScript Command", () => { | ||
| describe("Integration test", async () => { | ||
| let requiredMock: SinonMock; | ||
| let getWorkspaceRootMock: any; | ||
| let checkAppsSilent: SinonExpectation; | ||
| let installTruffle: SinonExpectation; | ||
| let commandContextMock: SinonMock; | ||
| let executeCommandMock: SinonExpectation; | ||
| let withProgressStub: SinonStub<[ProgressOptions, (progress: Progress<any>, token: CancellationToken) => any], any>; | ||
|
|
||
| beforeEach(() => { | ||
| requiredMock = mock(helpers.required); | ||
|
|
||
| getWorkspaceRootMock = stub(helpers, "getWorkspaceRoot"); | ||
| getWorkspaceRootMock.returns(uuid.v4()); | ||
|
|
||
| checkAppsSilent = requiredMock.expects("checkAppsSilent"); | ||
| installTruffle = requiredMock.expects("installTruffle"); | ||
|
|
||
| commandContextMock = mock(commands); | ||
| executeCommandMock = commandContextMock.expects("executeCommand"); | ||
|
|
||
| withProgressStub = stub(window, "withProgress"); | ||
| withProgressStub.callsFake(async (...args: any[]) => { | ||
| return args[1](); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| restore(); | ||
| }); | ||
|
|
||
| it("should not throw exception when script executes successfully", async () => { | ||
| // Arrange | ||
| checkAppsSilent.returns(true); | ||
| executeCommandMock.returns(uuid.v4()); | ||
|
|
||
| // Act | ||
| const scriptPath = join( | ||
| __dirname, | ||
| TestConstants.truffleCommandTestDataFolder, | ||
| TestConstants.truffleExecScriptExample | ||
| ); | ||
| await TruffleCommands.execScript(Uri.file(scriptPath)); | ||
|
|
||
| // Assert | ||
| assert.strictEqual(checkAppsSilent.calledOnce, true, "checkAppsSilent should be called once"); | ||
| assert.strictEqual(getWorkspaceRootMock.calledOnce, true, "getWorkspaceRoot should be called once"); | ||
| assert.strictEqual(installTruffle.called, false, "installTruffle should not be called"); | ||
| assert.strictEqual(executeCommandMock.called, true, "executeCommand should be called"); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| const TestContract = artifacts.require("./TestContract"); | ||
|
|
||
| const main = async (cb) => { | ||
| try { | ||
| const accounts = await web3.eth.getAccounts(); | ||
| } catch(err) { | ||
| console.log('Doh! ', err.message); | ||
| } | ||
| cb(); | ||
| } | ||
|
|
||
| module.exports = main; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,18 @@ import assert from "assert"; | |
| import sinon from "sinon"; | ||
| import {TruffleCommands} from "../src/commands/TruffleCommands"; | ||
| import {TruffleExtensionAdapter} from "../src/services/extensionAdapter"; | ||
| import {Uri} from "vscode"; | ||
|
|
||
| describe("TruffleExtensionAdapter", () => { | ||
| let buildContractsMock: sinon.SinonStub<any>; | ||
| let deployContractsMock: sinon.SinonStub<any>; | ||
| let execScriptMock: sinon.SinonStub<any>; | ||
| let truffleExtensionAdapter: TruffleExtensionAdapter; | ||
|
|
||
| beforeEach(() => { | ||
| buildContractsMock = sinon.stub(TruffleCommands, "buildContracts"); | ||
| deployContractsMock = sinon.stub(TruffleCommands, "deployContracts"); | ||
| execScriptMock = sinon.stub(TruffleCommands, "execScript"); | ||
|
|
||
| truffleExtensionAdapter = new TruffleExtensionAdapter(); | ||
| }); | ||
|
|
@@ -37,4 +40,12 @@ describe("TruffleExtensionAdapter", () => { | |
| // Assert | ||
| assert.strictEqual(deployContractsMock.calledOnce, true, "TruffleCommands.deployContracts should be called once"); | ||
| }); | ||
|
|
||
| it("exec method should call truffleCommands.execScript", async () => { | ||
| // Act | ||
| await truffleExtensionAdapter.execScript(Uri.file("./test.js")); | ||
|
|
||
| // Assert | ||
| assert.strictEqual(execScriptMock.calledOnce, true, "TruffleCommands.execScript should be called once"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly should this test mock something lower down and return a true/false on the success/failure of the exec call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly 🙃 do you mean whether the script actually executes (irrespective of its success / failure)? i feel this is more of a QOL of update and whether the script actually succeeds / fails doesn't matter too much as long as the output is accessible (as per the above)...it would be awesome if it auto-open to the output channel though |
||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you not want to do something with the output of this call?
Does this output to the outputChannel or similar? Debugging any issues will be problematic otherwise. Especially any exceptions (non 0 return codes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @michaeljohnbennett (apols for the delay), yup it does currently output to
Truffle for VSCodechannel...does that make sense from your perspective?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbluer, just a heads up: if we have more than one Truffle Project opened, or even a root directory without any truffle-config.js file, the function getWorkspaceRoot() might not work (e.g.: deploy function). The fix for that is on: fix/compile-from-working-dir