|
1 | 1 | import fs from 'fs'; |
| 2 | +import os from 'os'; |
| 3 | +import path from 'path'; |
2 | 4 | import test from 'ava'; |
3 | 5 | import execa from 'execa'; |
4 | 6 | import tempWrite from 'temp-write'; |
@@ -34,3 +36,31 @@ test('multiple newlines and tabs', async t => { |
34 | 36 | await execa('./cli.js', ['--string=,', '--replacement=\\n\\n\\t\\r', filePath]); |
35 | 37 | t.is(fs.readFileSync(filePath, 'utf8'), 'a\n\n\t\rb\n\n\t\rc'); |
36 | 38 | }); |
| 39 | + |
| 40 | +test('globs', async t => { |
| 41 | + const filePaths = [await tempWrite('foo bar foo', 'a.glob'), await tempWrite('foo bar foo', 'b.glob')]; |
| 42 | + const tmpdir = os.tmpdir(); |
| 43 | + |
| 44 | + await execa('./cli.js', ['--string=bar', '--replacement=foo', path.join(tmpdir, '*', '*.glob')]); |
| 45 | + t.is(fs.readFileSync(filePaths[0], 'utf8'), 'foo foo foo'); |
| 46 | + t.is(fs.readFileSync(filePaths[1], 'utf8'), 'foo foo foo'); |
| 47 | +}); |
| 48 | + |
| 49 | +test('no globs', async t => { |
| 50 | + const filePaths = [await tempWrite('foo bar foo', '*.glob'), await tempWrite('foo bar foo', 'foo.glob')]; |
| 51 | + const dirnames = filePaths.map(filePath => path.dirname(filePath)); |
| 52 | + |
| 53 | + await t.throwsAsync( |
| 54 | + execa('./cli.js', [ |
| 55 | + '--string=bar', |
| 56 | + '--replacement=foo', |
| 57 | + '--no-glob', |
| 58 | + path.join(dirnames[0], '*.glob'), |
| 59 | + path.join(dirnames[1], '*.glob') |
| 60 | + ]), |
| 61 | + { |
| 62 | + code: 1, |
| 63 | + message: /ENOENT/ |
| 64 | + } |
| 65 | + ); |
| 66 | +}); |
0 commit comments