easy_mock_io 0.1.0 copy "easy_mock_io: ^0.1.0" to clipboard
easy_mock_io: ^0.1.0 copied to clipboard

In-memory dart:io for Flutter tests. MockMemoryIO.init() swaps IOOverrides.global for a MemoryFileSystem, so File and Directory access runs in memory and never touches disk. File locks are no-ops (par [...]

easy_mock_io #

In-memory dart:io for Flutter tests. MockMemoryIO.init() replaces IOOverrides.global with a MemoryFileSystem, so every File / Directory your code under test touches runs in memory instead of hitting the real disk — no temp files to clean up, and tests stay isolated from each other.

Usage #

import 'package:easy_mock_io/easy_mock_io.dart';

setUp(() => MockMemoryIO.init());
tearDown(() => IOOverrides.global = null);

test('writes go to memory, not disk', () {
  File('/notes/todo.txt')
    ..createSync(recursive: true)
    ..writeAsStringSync('hi');

  expect(File('/notes/todo.txt').readAsStringSync(), 'hi');
});
  • MockMemoryIO.init([MemoryFileSystem? fs, MemoryIOConfig config]) installs the override. Pass a pre-seeded filesystem to start with files already present; omit it for an empty one. config controls the asset seeding and root path.
  • File locks are no-ops. lock / unlock (sync and async) return immediately, so tests that open the same path in parallel can't deadlock on an exclusive lock the memory filesystem wouldn't honour anyway.
  • Assets are seeded from the folder named by the UNIT_TEST_ASSETS environment variable, and /app_root is created up front.

init sets IOOverrides.global; reset it with IOOverrides.global = null in tearDown (or install a fresh one per test) so overrides don't leak.

0
likes
140
points
155
downloads

Documentation

API reference

Publisher

verified publisherahmedomar.com.ly

Weekly Downloads

In-memory dart:io for Flutter tests. MockMemoryIO.init() swaps IOOverrides.global for a MemoryFileSystem, so File and Directory access runs in memory and never touches disk. File locks are no-ops (parallel tests can't deadlock on the same file), the UNIT_TEST_ASSETS folder is seeded into the memory filesystem, and /app_root is pre-created.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

file

More

Packages that depend on easy_mock_io