This repository was archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Adding Truffle Exec context menu #73
Open
kevinbluer
wants to merge
2
commits into
develop
Choose a base branch
from
feature/truffle-exec
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -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>; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,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"); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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,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; |
This file contains hidden or 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 |
---|---|---|
|
@@ -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 |
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 VSCode
channel...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