-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
const path = require('path'); | ||
const path = require("path"); | ||
|
||
const { runTests } = require('vscode-test'); | ||
const { runTests } = require("vscode-test"); | ||
|
||
async function main() { | ||
try { | ||
// The folder containing the Extension Manifest package.json | ||
// Passed to `--extensionDevelopmentPath` | ||
const extensionDevelopmentPath = path.resolve(__dirname, '../'); | ||
try { | ||
// The folder containing the Extension Manifest package.json | ||
// Passed to `--extensionDevelopmentPath` | ||
const extensionDevelopmentPath = path.resolve(__dirname, "../"); | ||
|
||
// The path to the extension test script | ||
// Passed to --extensionTestsPath | ||
const extensionTestsPath = path.resolve(__dirname, './suite/index'); | ||
// The path to the extension test script | ||
// Passed to --extensionTestsPath | ||
const extensionTestsPath = path.resolve(__dirname, "./suite/index"); | ||
|
||
// Download VS Code, unzip it and run the integration test | ||
await runTests({ extensionDevelopmentPath, extensionTestsPath }); | ||
} catch (err) { | ||
console.error('Failed to run tests'); | ||
process.exit(1); | ||
} | ||
const launchArgs = [ | ||
`${path.resolve(__dirname, "../")}/test/fixtures/test.code-workspace`, | ||
"--disable-extensions", | ||
]; | ||
|
||
// Download VS Code, unzip it and run the integration test | ||
await runTests({ | ||
extensionDevelopmentPath, | ||
extensionTestsPath, | ||
launchArgs, | ||
}); | ||
} catch (err) { | ||
console.error("Failed to run tests"); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
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 |
---|---|---|
@@ -1,13 +1,93 @@ | ||
const assert = require('assert'); | ||
const assert = require("assert"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
// You can import and use all API from the 'vscode' module | ||
// as well as import your extension to test it | ||
const vscode = require('vscode'); | ||
const vscode = require("vscode"); | ||
const { before } = require("mocha"); | ||
// const myExtension = require('../extension'); | ||
|
||
suite('Extension Test Suite', () => { | ||
vscode.window.showInformationMessage('Start all tests.'); | ||
suite("Extension Test Suite", () => { | ||
vscode.window.showInformationMessage("Start all tests."); | ||
|
||
test('Sample test', () => { | ||
}); | ||
test("Should format file with extension", async function () { | ||
this.timeout(20000); | ||
await formatSameAsBladeFormatter( | ||
"index.blade.php", | ||
"formatted.index.blade.php" | ||
); | ||
}); | ||
|
||
test("Should ignore file if target listed in .bladeignore", async function () { | ||
this.timeout(20000); | ||
await formatSameAsBladeFormatter("ignore.blade.php", "ignore.blade.php"); | ||
}); | ||
}); | ||
|
||
async function formatSameAsBladeFormatter(file, formattedFile, options) { | ||
const { actual, source } = await format("project", file); | ||
const formatted = await getContent("project", formattedFile); | ||
assert.equal(actual, formatted); | ||
} | ||
|
||
async function getContent(workspaceFolderName, testFile) { | ||
const base = getWorkspaceFolderUri(workspaceFolderName); | ||
const absPath = path.join(base.fsPath, `${testFile}`); | ||
return fs.readFileSync(absPath).toString("utf-8"); | ||
} | ||
|
||
async function format(workspaceFolderName, testFile) { | ||
const base = getWorkspaceFolderUri(workspaceFolderName); | ||
const absPath = path.join(base.fsPath, testFile); | ||
const doc = await vscode.workspace.openTextDocument(absPath); | ||
const text = await doc.getText(); | ||
try { | ||
await vscode.window.showTextDocument(doc); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log(error); | ||
throw error; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.time(testFile); | ||
await waitForActivation("shufo.vscode-blade-formatter"); | ||
for (let i = 0; i < 3; i++) { | ||
await vscode.commands.executeCommand("editor.action.formatDocument"); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.timeEnd(testFile); | ||
|
||
return { actual: await doc.getText(), source: text }; | ||
} | ||
|
||
function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function waitForActivation(extensionId) { | ||
let i = 0; | ||
while (vscode.extensions.getExtension(extensionId).isActive === false) { | ||
if (i === 10) { | ||
break; | ||
} | ||
|
||
await sleep(1000); | ||
i++; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
const getWorkspaceFolderUri = (workspaceFolderName) => { | ||
const workspaceFolder = vscode.workspace.workspaceFolders.find((folder) => { | ||
return folder.name === workspaceFolderName; | ||
}); | ||
if (!workspaceFolder) { | ||
throw new Error( | ||
"Folder not found in workspace. Did you forget to add the test folder to test.code-workspace?" | ||
); | ||
} | ||
return workspaceFolder.uri; | ||
}; |