@@ -6,7 +6,6 @@ import { isWindows } from '@theia/core/lib/common/os';
66import { FileUri } from '@theia/core/lib/node/file-uri';
77import { Container } from '@theia/core/shared/inversify';
88import { expect } from 'chai';
9- import { rejects } from 'node:assert/strict';
109import { promises as fs } from 'node:fs';
1110import { basename, join } from 'node:path';
1211import { sync as rimrafSync } from 'rimraf';
@@ -67,19 +66,30 @@ describe('isAccessibleSketchPath', () => {
6766 expect(actual).to.be.equal(aSketchFilePath);
6867 });
6968
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 () {
7770 const sketchFolderPath = join(testDirPath, 'my_sketch');
7871 const mainSketchFilePath = join(sketchFolderPath, 'my_sketch.ino');
7972 await fs.mkdir(sketchFolderPath, { recursive: true });
8073 await fs.writeFile(mainSketchFilePath, '', { encoding: 'utf8' });
8174 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+ }
8393 const actual = await isAccessibleSketchPath(sketchFolderPath);
8494 expect(actual).to.be.equal(mainSketchFilePath);
8595 });
0 commit comments