forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metro-bundler: add fs#writeFileSync to the mock
Reviewed By: rafeca Differential Revision: D5931412 fbshipit-source-id: 2b51617b57963c424446b04e9381e6500323af56
- Loading branch information
1 parent
7320ca5
commit b3fc642
Showing
2 changed files
with
93 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails oncall+javascript_foundation | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/* eslint-disable no-unclear-flowtypes */ | ||
|
||
declare var jest: any; | ||
declare var describe: any; | ||
declare var it: any; | ||
|
||
jest.mock('fs'); | ||
|
||
const fs = require('fs'); | ||
|
||
describe('fs mock', () => { | ||
describe('writeFileSync()', () => { | ||
it('stores content correctly', () => { | ||
fs.writeFileSync('/test', 'foobar', 'utf8'); | ||
const content = fs.readFileSync('/test', 'utf8'); | ||
expect(content).toEqual('foobar'); | ||
}); | ||
|
||
it('fails on missing path', () => { | ||
expect(() => | ||
fs.writeFileSync('/dir/test', 'foobar', 'utf8'), | ||
).toThrowError('ENOENT: no such file or directory'); | ||
}); | ||
}); | ||
|
||
describe('mkdirSync()', () => { | ||
it('creates folders that we can write files in', () => { | ||
fs.mkdirSync('/dir', 0o777); | ||
fs.writeFileSync('/dir/test', 'foobar', 'utf8'); | ||
const content = fs.readFileSync('/dir/test', 'utf8'); | ||
expect(content).toEqual('foobar'); | ||
}); | ||
}); | ||
}); |