This repository was archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
Automate toolkit test set up in a webview extension environment #317
Merged
hawkticehurst
merged 9 commits into
microsoft:main
from
hawkticehurst:test-setup-automation
Jan 18, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b149c61
Format eslint tsconfig file
hawkticehurst 816e2c3
Add scripts dir to eslint ignore file
hawkticehurst b5eb8e1
Create scripts folder and initial setup-webview-test-env script
hawkticehurst d946b26
Create setup-webview-test-env script
hawkticehurst 79a89b6
Create test:webview npm script
hawkticehurst 18a4507
Add prettier override to increase the print width of the script file
hawkticehurst f2c2495
Add test-webview folder to various config ignore files and sections
hawkticehurst 5799387
Add test-webview folder to various config ignore files and sections
hawkticehurst b852e10
Clean up script code
hawkticehurst 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ node_modules/ | |
| dist/ | ||
| storybook-static/ | ||
|
|
||
| # Tests | ||
| test-webview | ||
|
|
||
| # Misc | ||
| .DS_Store | ||
| .vscode | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ CONTRIBUTING.md | |
| # Tests | ||
| *.spec.* | ||
| coverage/ | ||
| test-webview | ||
|
|
||
| # Builds | ||
| build/ | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ build/ | |
| dist/ | ||
| storybook-static/ | ||
|
|
||
| # Tests | ||
| test-webview | ||
|
|
||
| # Misc | ||
| .DS_Store | ||
| .vscode | ||
|
|
||
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,124 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const {exec} = require('child_process'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const process = require('process'); | ||
| const util = require('util'); | ||
|
|
||
| const execPromise = util.promisify(exec); | ||
|
|
||
| async function main() { | ||
| // Empty print line to pretty-ify command line output | ||
| console.log(); | ||
|
|
||
| // Copy webview test environment locally if it does not already exist | ||
| if (!fs.existsSync('./test-webview')) { | ||
| try { | ||
| console.log(color(['dim'], 'Copying webview test environment locally...')); | ||
| await execShellCommand('npx degit microsoft/vscode-webview-ui-toolkit-samples/all-components test-webview'); | ||
| } catch (err) { | ||
| console.log(`${color(['red'], 'Error: Could not copy webview test environment locally')}\n ${err}`); | ||
| process.exit(); | ||
| } | ||
| } | ||
|
|
||
| // Install the webview test environment dependencies if they do not exist | ||
| if (!fs.existsSync('./test-webview/node_modules')) { | ||
| try { | ||
| console.log(color(['dim'], 'Installing webview test environment dependencies...')); | ||
| await execShellCommand('cd ./test-webview && npm install'); | ||
| } catch (err) { | ||
| console.log(`${color(['red'], 'Error: Could not install webview test environment dependencies')}\n ${err}`); | ||
| process.exit(); | ||
| } | ||
| } | ||
|
|
||
| // Copy latest toolkit build into the webview test environment | ||
| console.log(color(['dim'], 'Copying latest toolkit build into webview test environment...')); | ||
| delDir('./test-webview/node_modules/@vscode/webview-ui-toolkit/dist'); | ||
| createDir('./test-webview/node_modules/@vscode/webview-ui-toolkit/dist'); | ||
| copyDir('./dist', './test-webview/node_modules/@vscode/webview-ui-toolkit'); | ||
|
|
||
| // Print success and next steps messages | ||
| console.log(); | ||
| console.log(color(['bold', 'green'], 'Webview test environment successfully configured!')); | ||
| console.log(); | ||
| console.log('Next steps:'); | ||
| console.log(` 1. Open the ${color(['cyan'], 'test-webview')} folder in a new VS Code window`); | ||
| console.log(` 2. Press ${color(['cyan'], 'F5')} to open the webview test extension with the most recent toolkit build loaded`); | ||
| console.log(` 3. Run the "${color(['cyan'], 'Webview UI Toolkit: All Components')}" command using the VS Code command palette`); | ||
daviddossett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| console.log(); | ||
| } | ||
|
|
||
| async function execShellCommand(command) { | ||
| return await execPromise(command); | ||
| } | ||
|
|
||
| function delDir(path) { | ||
| if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) { | ||
| fs.readdirSync(path).forEach(function (file, index) { | ||
| const currPath = path + '/' + file; | ||
| if (fs.lstatSync(currPath).isDirectory()) { | ||
| delDir(currPath); | ||
| } else { | ||
| fs.unlinkSync(currPath); | ||
| } | ||
| }); | ||
| fs.rmdirSync(path); | ||
| } | ||
| } | ||
|
|
||
| function createDir(dir) { | ||
| if (!fs.existsSync(dir)) { | ||
| fs.mkdirSync(dir); | ||
| } | ||
| } | ||
|
|
||
| function copyDir(source, target) { | ||
| let files = []; | ||
| const targetFolder = path.join(target, path.basename(source)); | ||
| if (!fs.existsSync(targetFolder)) { | ||
| fs.mkdirSync(targetFolder); | ||
| } | ||
| if (fs.lstatSync(source).isDirectory()) { | ||
| files = fs.readdirSync(source); | ||
| files.forEach(function (file) { | ||
| const curSource = path.join(source, file); | ||
| if (fs.lstatSync(curSource).isDirectory()) { | ||
| copyDir(curSource, targetFolder); | ||
| } else { | ||
| copyFileSync(curSource, targetFolder); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function copyFileSync(source, target) { | ||
| let targetFile = target; | ||
| if (fs.existsSync(target)) { | ||
| if (fs.lstatSync(target).isDirectory()) { | ||
| targetFile = path.join(target, path.basename(source)); | ||
| } | ||
| } | ||
| fs.writeFileSync(targetFile, fs.readFileSync(source)); | ||
| } | ||
|
|
||
| const colors = { | ||
| reset: '\x1b[0m', | ||
| bold: '\x1b[1m', | ||
| dim: '\x1b[2m', | ||
| red: '\x1b[31m', | ||
| green: '\x1b[32m', | ||
| cyan: '\x1b[36m', | ||
| }; | ||
|
|
||
| function color(opts, text) { | ||
| let colorString = ''; | ||
| for (const opt of opts) { | ||
| colorString += colors[opt]; | ||
| } | ||
| return `${colorString}${text}${colors.reset}`; | ||
| } | ||
|
|
||
| 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "include": ["src"], | ||
| "exclude": ["node_modules"] | ||
| } | ||
| "extends": "./tsconfig.json", | ||
| "include": ["src"], | ||
| "exclude": ["node_modules", "test-webview"] | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.