|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
2 | 2 | // See LICENSE in the project root for license information.
|
3 | 3 |
|
| 4 | +import fs from 'node:fs'; |
| 5 | + |
4 | 6 | import { FileSystem } from '../FileSystem';
|
5 | 7 | import { PosixModeBits } from '../PosixModeBits';
|
6 | 8 |
|
7 |
| -// The PosixModeBits are intended to be used with bitwise operations. |
8 |
| -/* eslint-disable no-bitwise */ |
| 9 | +describe(FileSystem.name, () => { |
| 10 | + test(FileSystem.formatPosixModeBits.name, () => { |
| 11 | + // The PosixModeBits are intended to be used with bitwise operations. |
| 12 | + /* eslint-disable no-bitwise */ |
| 13 | + let modeBits: number = PosixModeBits.AllRead | PosixModeBits.AllWrite; |
| 14 | + |
| 15 | + expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-rw-rw-rw-'); |
| 16 | + |
| 17 | + modeBits |= PosixModeBits.GroupExecute; |
| 18 | + expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-rw-rwxrw-'); |
9 | 19 |
|
10 |
| -test('PosixModeBits tests', () => { |
11 |
| - let modeBits: number = PosixModeBits.AllRead | PosixModeBits.AllWrite; |
| 20 | + // Add the group execute bit |
| 21 | + modeBits |= PosixModeBits.OthersExecute; |
| 22 | + expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-rw-rwxrwx'); |
12 | 23 |
|
13 |
| - expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-rw-rw-rw-'); |
| 24 | + // Add the group execute bit |
| 25 | + modeBits &= ~PosixModeBits.AllWrite; |
| 26 | + expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-r--r-xr-x'); |
| 27 | + /* eslint-enable no-bitwise */ |
| 28 | + }); |
14 | 29 |
|
15 |
| - modeBits |= PosixModeBits.GroupExecute; |
16 |
| - expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-rw-rwxrw-'); |
| 30 | + describe(FileSystem.isErrnoException.name, () => { |
| 31 | + test('Should return false for a non-ErrnoException', () => { |
| 32 | + const error: Error = new Error('Test error'); |
| 33 | + expect(FileSystem.isErrnoException(error)).toBe(false); |
| 34 | + }); |
17 | 35 |
|
18 |
| - // Add the group execute bit |
19 |
| - modeBits |= PosixModeBits.OthersExecute; |
20 |
| - expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-rw-rwxrwx'); |
| 36 | + test('Should return true for an error on a path call', () => { |
| 37 | + expect.assertions(1); |
| 38 | + try { |
| 39 | + fs.openSync(`${__dirname}/nonexistent.txt`, 'r'); |
| 40
A3FA
td> | + } catch (error) { |
| 41 | + expect(FileSystem.isErrnoException(error)).toBe(true); |
| 42 | + } |
| 43 | + }); |
21 | 44 |
|
22 |
| - // Add the group execute bit |
23 |
| - modeBits &= ~PosixModeBits.AllWrite; |
24 |
| - expect(FileSystem.formatPosixModeBits(modeBits)).toEqual('-r--r-xr-x'); |
| 45 | + test('Should return true for an error on a file descriptor call', () => { |
| 46 | + const buffer: Buffer = Buffer.allocUnsafeSlow(1024); |
| 47 | + expect.assertions(1); |
| 48 | + try { |
| 49 | + fs.readSync(11, buffer, 0, buffer.length, -1); |
| 50 | + } catch (error) { |
| 51 | + expect(FileSystem.isErrnoException(error)).toBe(true); |
| 52 | + } |
| 53 | + }); |
| 54 | + }); |
25 | 55 | });
|
0 commit comments