-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import os from 'os'; | ||
import path from 'path'; | ||
import HasteMap from 'jest-haste-map'; | ||
import {cleanup, writeFiles} from '../Utils'; | ||
|
||
const DIR = path.resolve(os.tmpdir(), 'haste_map_size'); | ||
|
||
beforeEach(() => { | ||
cleanup(DIR); | ||
writeFiles(DIR, { | ||
'file.js': '"abc"', | ||
}); | ||
}); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
const options = { | ||
extensions: ['js'], | ||
forceNodeFilesystemAPI: true, | ||
ignorePattern: / ^/, | ||
maxWorkers: 2, | ||
mocksPattern: '', | ||
name: 'tmp', | ||
platforms: [], | ||
retainAllFiles: true, | ||
rootDir: DIR, | ||
roots: [DIR], | ||
useWatchman: false, | ||
watch: false, | ||
}; | ||
|
||
test('reports the correct file size', async () => { | ||
const hasteMap = new HasteMap(options); | ||
const hasteFS = (await hasteMap.build()).hasteFS; | ||
expect(hasteFS.getSize(path.join(DIR, 'file.js'))).toBe(5); | ||
}); | ||
|
||
test('updates the file size when a file changes', async () => { | ||
const hasteMap = new HasteMap({...options, watch: true}); | ||
await hasteMap.build(); | ||
|
||
writeFiles(DIR, { | ||
'file.js': '"asdf"', | ||
}); | ||
const {hasteFS} = await new Promise(resolve => | ||
hasteMap.once('change', resolve), | ||
); | ||
expect(hasteFS.getSize(path.join(DIR, 'file.js'))).toBe(6); | ||
}); |