@@ -6,7 +6,6 @@ import { isWindows } from '@theia/core/lib/common/os';
6
6
import { FileUri } from '@theia/core/lib/node/file-uri' ;
7
7
import { Container } from '@theia/core/shared/inversify' ;
8
8
import { expect } from 'chai' ;
9
- import { rejects } from 'node:assert/strict' ;
10
9
import { promises as fs } from 'node:fs' ;
11
10
import { basename , join } from 'node:path' ;
12
11
import { sync as rimrafSync } from 'rimraf' ;
@@ -67,19 +66,30 @@ describe('isAccessibleSketchPath', () => {
67
66
expect ( actual ) . to . be . equal ( aSketchFilePath ) ;
68
67
} ) ;
69
68
70
- it ( 'should ignore EACCESS (non-Windows)' , async function ( ) {
71
- if ( isWindows ) {
72
- // `stat` syscall does not result in an EACCESS on Windows after stripping the file permissions.
73
- // an `open` syscall would, but IDE2 on purpose does not check the files.
74
- // the sketch files are provided by the CLI after loading the sketch.
75
- return this . skip ( ) ;
76
- }
69
+ it ( 'should ignore EACCESS' , async function ( ) {
77
70
const sketchFolderPath = join ( testDirPath , 'my_sketch' ) ;
78
71
const mainSketchFilePath = join ( sketchFolderPath , 'my_sketch.ino' ) ;
79
72
await fs . mkdir ( sketchFolderPath , { recursive : true } ) ;
80
73
await fs . writeFile ( mainSketchFilePath , '' , { encoding : 'utf8' } ) ;
81
74
await fs . chmod ( mainSketchFilePath , 0o000 ) ; // remove all permissions
82
- await rejects ( fs . readFile ( mainSketchFilePath ) , ErrnoException . isEACCES ) ;
75
+ try {
76
+ await fs . readFile ( mainSketchFilePath ) ;
77
+ // If reading the file without sufficient permissions does not result in EACCESS error, do not run the test.
78
+ // For example, a `stat` syscall does not result in an EACCESS on Windows after stripping the file permissions.
79
+ // an `open` syscall would, but IDE2 on purpose does not check the files.
80
+ // the sketch files are provided by the CLI after loading the sketch.
81
+ console . info (
82
+ 'Skip. Reading the file content without permissions was successful.'
83
+ ) ;
84
+ return this . skip ( ) ;
85
+ } catch ( err ) {
86
+ expect (
87
+ ErrnoException . isEACCES ( err ) ,
88
+ `Expected an error with EACCES code. Got: ${
89
+ typeof err === 'object' ? JSON . stringify ( err ) : err
90
+ } `
91
+ ) . to . be . true ;
92
+ }
83
93
const actual = await isAccessibleSketchPath ( sketchFolderPath ) ;
84
94
expect ( actual ) . to . be . equal ( mainSketchFilePath ) ;
85
95
} ) ;
0 commit comments