-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
e5c1280
commit 4862daa
Showing
2 changed files
with
54 additions
and
1 deletion.
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,53 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const metatests = require('metatests'); | ||
const WriteStream = require('../lib/fs-writable'); | ||
|
||
|
||
metatests.testSync('fs-writable / create', test => { | ||
const TEST_FILENAME = './create'; | ||
|
||
new WriteStream(TEST_FILENAME); | ||
|
||
test.throws(() => new WriteStream()); | ||
test.throws(() => new WriteStream(1)); | ||
test.throws(() => new WriteStream(true)); | ||
|
||
test.throws(() => new WriteStream(TEST_FILENAME, { start: -1 })); | ||
|
||
fs.unlinkSync(TEST_FILENAME); | ||
}); | ||
|
||
metatests.test('fs-writable / open', test => { | ||
const TEST_FILENAME = './open'; | ||
|
||
test.plan(2); | ||
|
||
const stream = new WriteStream(TEST_FILENAME); | ||
stream.on('open', () => test.pass('open')); | ||
stream.on('ready', () => test.pass('ready')); | ||
|
||
test.on('done', () => fs.unlinkSync(TEST_FILENAME)); | ||
}); | ||
|
||
metatests.test('fs-writable / write', test => { | ||
const TEST_FILENAME = './write'; | ||
|
||
test.plan(1); | ||
|
||
const stream = new WriteStream(TEST_FILENAME); | ||
|
||
stream.write('123'); | ||
stream.write('456'); | ||
stream.cork(); | ||
stream.write('7'); | ||
stream.write('8'); | ||
stream.uncork(); | ||
stream.end('9', () => { | ||
const writeData = fs.readFileSync(TEST_FILENAME).toString(); | ||
fs.unlinkSync(TEST_FILENAME); | ||
test.strictSame(writeData, '123456789'); | ||
}); | ||
}); | ||
|