-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed testing support for non-sync backends Removed testing support for non-prop backends
- Loading branch information
Showing
24 changed files
with
234 additions
and
540 deletions.
There are no files selected for viewing
This file contains 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,39 +1,31 @@ | ||
import { Stats, FileType, type BigIntStats } from '../src/stats'; | ||
import { configure as _configure, fs, InMemory, AsyncMirror, Overlay } from '../src/index'; | ||
import { fs } from '../src/index'; | ||
import * as path from 'path'; | ||
import { statSync, readFileSync, readdirSync } from 'fs'; | ||
import type { BackendConfig } from '../src/backends/backend'; | ||
|
||
export const fixturesDir = 'test/fixtures/files/node'; | ||
|
||
function copy(_fs: typeof fs, _p: string) { | ||
const p = path.posix.resolve('/', path.posix.relative(fixturesDir, _p)); | ||
function copy(_p: string) { | ||
const p = path.posix.relative(fixturesDir, _p); | ||
const stats = statSync(_p); | ||
|
||
if (!stats.isDirectory()) { | ||
_fs.writeFileSync(p, readFileSync(_p)); | ||
fs.writeFileSync(p, readFileSync(_p)); | ||
return; | ||
} | ||
|
||
if (p != '/') { | ||
_fs.mkdirSync(p); | ||
fs.mkdirSync(p); | ||
} | ||
for (const file of readdirSync(_p)) { | ||
copy(_fs, path.join(_p, file)); | ||
copy(path.join(_p, file)); | ||
} | ||
} | ||
|
||
export async function configure(config: BackendConfig): Promise<void> { | ||
await _configure(config); | ||
copy(fs, fixturesDir); | ||
} | ||
copy(fixturesDir); | ||
|
||
export { fs }; | ||
|
||
export function createMockStats(mode: number | bigint): Stats | BigIntStats { | ||
return new Stats(FileType.FILE, -1, mode); | ||
} | ||
|
||
const tests: BackendConfig[] = [{ backend: AsyncMirror, sync: InMemory, async: InMemory }, { backend: InMemory }, { backend: Overlay, readable: InMemory, writable: InMemory }]; | ||
|
||
export const backends: [string, BackendConfig][] = tests.map(test => [test.backend.name, test]); |
This file contains 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 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 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,45 +1,20 @@ | ||
import { backends, fs, configure, fixturesDir } from '../common'; | ||
import * as path from 'path'; | ||
import { fs } from '../common'; | ||
|
||
describe.each(backends)('%s fs.exists', (name, options) => { | ||
const configured = configure(options); | ||
let exists: boolean; | ||
let doesNotExist: boolean; | ||
const f = path.join(fixturesDir, 'x.txt'); | ||
|
||
beforeAll(() => { | ||
return new Promise<void>(resolve => { | ||
fs.exists(f, y => { | ||
exists = y; | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
|
||
beforeAll(() => { | ||
return new Promise<void>(resolve => { | ||
fs.exists(f + '-NO', y => { | ||
doesNotExist = y; | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
describe('fs.exists', () => { | ||
const f = 'x.txt'; | ||
|
||
it('should return true for an existing file', async () => { | ||
await configured; | ||
const exists = await fs.promises.exists(f); | ||
expect(exists).toBe(true); | ||
}); | ||
|
||
it('should return false for a non-existent file', async () => { | ||
await configured; | ||
expect(doesNotExist).toBe(false); | ||
const exists = await fs.promises.exists(f + '-NO'); | ||
expect(exists).toBe(false); | ||
}); | ||
|
||
it('should have sync methods that behave the same', async () => { | ||
await configured; | ||
if (fs.getMount('/').metadata.synchronous) { | ||
expect(fs.existsSync(f)).toBe(true); | ||
expect(fs.existsSync(f + '-NO')).toBe(false); | ||
} | ||
expect(fs.existsSync(f)).toBe(true); | ||
expect(fs.existsSync(f + '-NO')).toBe(false); | ||
}); | ||
}); |
This file contains 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,36 +1,26 @@ | ||
import { backends, fs, configure } from '../common'; | ||
import * as path from 'path'; | ||
// Import promisify | ||
import { fixturesDir } from '../common'; | ||
import { fs } from '../common'; | ||
import { FileHandle } from '../../src/emulation/promises'; | ||
|
||
describe.each(backends)('%s fs.fileSync', (name, options) => { | ||
const configured = configure(options); | ||
const file = path.join(fixturesDir, 'a.js'); | ||
describe('fs.fileSync', () => { | ||
const file = 'a.js'; | ||
|
||
if (!fs.getMount('/').metadata.readonly) { | ||
let handle: FileHandle; | ||
let handle: FileHandle; | ||
|
||
beforeAll(async () => { | ||
handle = await fs.promises.open(file, 'a', 0o777); | ||
}); | ||
beforeAll(async () => { | ||
handle = await fs.promises.open(file, 'a', 0o777); | ||
}); | ||
|
||
if (fs.getMount('/').metadata.synchronous) { | ||
it('should synchronize file data changes (sync)', async () => { | ||
await configured; | ||
fs.fdatasyncSync(handle.fd); | ||
fs.fsyncSync(handle.fd); | ||
}); | ||
} | ||
it('should synchronize file data changes (sync)', async () => { | ||
fs.fdatasyncSync(handle.fd); | ||
fs.fsyncSync(handle.fd); | ||
}); | ||
|
||
it('should synchronize file data changes (async)', async () => { | ||
await configured; | ||
await handle.datasync(); | ||
await handle.sync(); | ||
}); | ||
it('should synchronize file data changes (async)', async () => { | ||
await handle.datasync(); | ||
await handle.sync(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await handle.close(); | ||
}); | ||
} | ||
afterAll(async () => { | ||
await handle.close(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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,40 +1,29 @@ | ||
import { backends, fs, configure } from '../common'; | ||
import { tmpDir, fixturesDir } from '../common'; | ||
|
||
describe.each(backends)('%s fs.mkdir', (name, options) => { | ||
const configured = configure(options); | ||
|
||
if (!fs.getMount('/').metadata.readonly) { | ||
const pathname1 = tmpDir + '/mkdir-test1'; | ||
|
||
it('should create a directory and verify its existence', async () => { | ||
await configured; | ||
|
||
await fs.promises.mkdir(pathname1); | ||
const exists = await fs.promises.exists(pathname1); | ||
expect(exists).toBe(true); | ||
}); | ||
|
||
const pathname2 = tmpDir + '/mkdir-test2'; | ||
|
||
it('should create a directory with custom permissions and verify its existence', async () => { | ||
await configured; | ||
|
||
await fs.promises.mkdir(pathname2, 0o777); | ||
const exists = await fs.promises.exists(pathname2); | ||
expect(exists).toBe(true); | ||
}); | ||
|
||
const pathname3 = tmpDir + '/mkdir-test3/again'; | ||
|
||
it('should not be able to create multi-level directories', async () => { | ||
await configured; | ||
|
||
try { | ||
await fs.promises.mkdir(pathname3, 0o777); | ||
} catch (err) { | ||
expect(err).not.toBeNull(); | ||
} | ||
}); | ||
} | ||
import { fs } from '../common'; | ||
|
||
describe('fs.mkdir', () => { | ||
const pathname1 = 'mkdir-test1'; | ||
|
||
it('should create a directory and verify its existence', async () => { | ||
await fs.promises.mkdir(pathname1); | ||
const exists = await fs.promises.exists(pathname1); | ||
expect(exists).toBe(true); | ||
}); | ||
|
||
const pathname2 = 'mkdir-test2'; | ||
|
||
it('should create a directory with custom permissions and verify its existence', async () => { | ||
await fs.promises.mkdir(pathname2, 0o777); | ||
const exists = await fs.promises.exists(pathname2); | ||
expect(exists).toBe(true); | ||
}); | ||
|
||
const pathname3 = 'mkdir-test3/again'; | ||
|
||
it('should not be able to create multi-level directories', async () => { | ||
try { | ||
await fs.promises.mkdir(pathname3, 0o777); | ||
} catch (err) { | ||
expect(err).not.toBeNull(); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.