File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 - name : Get NPM Version
2727 id : package-version
2828 uses : martinbeentjes/npm-get-version-action@v1.3.1
29+ - name : Run Tests
30+ run : xvfb-run -a yarn test
2931 - name : Check if version exists
3032 id : check-version
3133 env :
Original file line number Diff line number Diff line change 1+ name : Unit Tests
2+
3+ on :
4+ push :
5+ branches : ["main", "master"]
6+ pull_request :
7+ branches : ["main", "master"]
8+
9+ jobs :
10+ test :
11+ strategy :
12+ matrix :
13+ os : [ubuntu-latest, windows-latest, macos-latest]
14+ runs-on : ${{ matrix.os }}
15+ name : Test on ${{ matrix.os }}
16+ steps :
17+ - uses : actions/checkout@v4
18+ - name : Use Node.js 22
19+ uses : actions/setup-node@v4
20+ with :
21+ node-version : 22
22+ cache : ' yarn'
23+ - name : Install dependencies
24+ run : yarn install --frozen-lockfile
25+ - name : Run Tests (Linux)
26+ if : runner.os == 'Linux'
27+ run : xvfb-run -a yarn test
28+ - name : Run Tests (Windows/Mac)
29+ if : runner.os != 'Linux'
30+ run : yarn test
Original file line number Diff line number Diff line change 7373 "compile" : " tsc -p ./" ,
7474 "lint" : " eslint src --ext ts" ,
7575 "watch" : " tsc -watch -p ./" ,
76- "pretest" : " npm run compile && npm run lint " ,
76+ "pretest" : " npm run compile" ,
7777 "test" : " node ./out/test/runTest.js"
7878 },
7979 "devDependencies" : {
8888 "lodash" : " ^4.17.21" ,
8989 "mocha" : " ^11.7.5" ,
9090 "typescript" : " ^5.9.3" ,
91- "vscode- test" : " ^1.3.0 "
91+ "@ vscode/ test-electron " : " ^2.4.1 "
9292 },
9393 "dependencies" : {
9494 "@types/temp" : " ^0.9.4" ,
Original file line number Diff line number Diff line change 1+ import * as path from "path" ;
2+ import { runTests } from "@vscode/test-electron" ;
3+
4+ async function main ( ) {
5+ try {
6+ // The folder containing the Extension Manifest package.json
7+ // Passed to `--extensionDevelopmentPath`
8+ const extensionDevelopmentPath = path . resolve ( __dirname , "../../" ) ;
9+
10+ // The path to test runner
11+ // Passed to --extensionTestsPath
12+ const extensionTestsPath = path . resolve ( __dirname , "./suite/index" ) ;
13+
14+ // Download VS Code, unzip it and run the integration test
15+ await runTests ( { extensionDevelopmentPath, extensionTestsPath } ) ;
16+ } catch ( err ) {
17+ console . error ( "Failed to run tests" ) ;
18+ process . exit ( 1 ) ;
19+ }
20+ }
21+
22+ main ( ) ;
Original file line number Diff line number Diff line change 1+ import * as assert from "assert" ;
2+ import * as vscode from "vscode" ;
3+ import { getConfig } from "../../config" ;
4+
5+ suite ( "Configuration Test Suite" , ( ) => {
6+ vscode . window . showInformationMessage ( "Start config tests." ) ;
7+
8+ test ( "Default configuration values" , ( ) => {
9+ const config = getConfig ( ) ;
10+ assert . strictEqual ( config . ps2pdf , "ps2pdf" ) ;
11+ assert . strictEqual ( config . pdftocairo , "pdftocairo" ) ;
12+ assert . strictEqual ( config . pdfinfo , "pdfinfo" ) ;
13+ } ) ;
14+ test ( "Configuration should be readable" , ( ) => {
15+ const config = vscode . workspace . getConfiguration ( "postscript-preview" ) ;
16+ assert . ok ( config . has ( "path.ps2pdf" ) ) ;
17+ assert . ok ( config . has ( "path.pdftocairo" ) ) ;
18+ } ) ;
19+ } ) ;
Original file line number Diff line number Diff line change 1+ import * as assert from "assert" ;
2+ import * as vscode from "vscode" ;
3+
4+ suite ( "Extension Test Suite" , ( ) => {
5+ vscode . window . showInformationMessage ( "Start extension tests." ) ;
6+
7+ test ( "Extension should be present" , ( ) => {
8+ assert . ok (
9+ vscode . extensions . getExtension ( "ahnafnafee.postscript-preview" )
10+ ) ;
11+ } ) ;
12+
13+ test ( "Extension should activate" , async ( ) => {
14+ const ext = vscode . extensions . getExtension (
15+ "ahnafnafee.postscript-preview"
16+ ) ;
17+ assert . ok ( ext , "Extension not found" ) ;
18+
19+ // Activate if not active
20+ if ( ! ext . isActive ) {
21+ await ext . activate ( ) ;
22+ }
23+
24+ assert . strictEqual ( ext . isActive , true ) ;
25+ } ) ;
26+
27+ test ( "Command should be registered" , async ( ) => {
28+ const commands = await vscode . commands . getCommands ( true ) ;
29+ assert . ok ( commands . includes ( "postscript-preview.sidePreview" ) ) ;
30+ } ) ;
31+ } ) ;
Original file line number Diff line number Diff line change 1+ import * as path from "path" ;
2+ import * as Mocha from "mocha" ;
3+ import { glob } from "glob" ;
4+
5+ export async function run ( ) : Promise < void > {
6+ // Create the mocha test
7+ const mocha = new Mocha ( {
8+ ui : "tdd" ,
9+ color : true ,
10+ } ) ;
11+
12+ const testsRoot = path . resolve ( __dirname , ".." ) ;
13+
14+ // Use glob to find all files ending in .test.js
15+ const files = await glob ( "**/**.test.js" , { cwd : testsRoot } ) ;
16+
17+ // Add files to the test suite
18+ files . forEach ( ( f ) => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ;
19+
20+ return new Promise ( ( resolve , reject ) => {
21+ try {
22+ // Run the mocha test
23+ mocha . run ( ( failures ) => {
24+ if ( failures > 0 ) {
25+ reject ( new Error ( `${ failures } tests failed.` ) ) ;
26+ } else {
27+ resolve ( ) ;
28+ }
29+ } ) ;
30+ } catch ( err ) {
31+ console . error ( err ) ;
32+ reject ( err ) ;
33+ }
34+ } ) ;
35+ }
You can’t perform that action at this time.
0 commit comments