|
1 |
| -var assert = require('assert'), |
2 |
| - fs = require('fs'), |
3 |
| - saneEmitter, |
4 |
| - sanity = 'ire(\'assert\')'; |
| 1 | +'use strict'; |
5 | 2 |
|
6 |
| -saneEmitter = fs.createReadStream(__filename, { start: 17, end: 29 }); |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const fs = require('fs'); |
| 6 | +const path = require('path'); |
| 7 | +const tempFile = path.join(common.tmpDir, 'fs-non-number-arguments-throw'); |
7 | 8 |
|
8 |
| -assert.throws(function () { |
9 |
| - fs.createReadStream(__filename, { start: "17", end: 29 }); |
| 9 | +common.refreshTmpDir(); |
| 10 | +fs.writeFileSync(tempFile, 'abc\ndef'); |
| 11 | + |
| 12 | +// a sanity check when using numbers instead of strings |
| 13 | +const sanity = 'def'; |
| 14 | +const saneEmitter = fs.createReadStream(tempFile, { start: 4, end: 6 }); |
| 15 | + |
| 16 | +assert.throws(function() { |
| 17 | + fs.createReadStream(tempFile, { start: '4', end: 6 }); |
10 | 18 | }, "start as string didn't throw an error for createReadStream");
|
11 | 19 |
|
12 |
| -assert.throws(function () { |
13 |
| - fs.createReadStream(__filename, { start: 17, end: "29" }); |
| 20 | +assert.throws(function() { |
| 21 | + fs.createReadStream(tempFile, { start: 4, end: '6' }); |
14 | 22 | }, "end as string didn't throw an error");
|
15 | 23 |
|
16 |
| -assert.throws(function () { |
17 |
| - fs.createWriteStream(__filename, { start: "17" }); |
| 24 | +assert.throws(function() { |
| 25 | + fs.createWriteStream(tempFile, { start: '4' }); |
18 | 26 | }, "start as string didn't throw an error for createWriteStream");
|
19 | 27 |
|
20 |
| -saneEmitter.on('data', function (data) { |
21 |
| - // a sanity check when using numbers instead of strings |
| 28 | +saneEmitter.on('data', function(data) { |
22 | 29 | assert.strictEqual(sanity, data.toString('utf8'), 'read ' +
|
23 | 30 | data.toString('utf8') + ' instead of ' + sanity);
|
24 | 31 | });
|
0 commit comments