|
1 |
| -/* global describe, it, beforeEach */ |
| 1 | +/* global describe, it, beforeEach, afterEach */ |
2 | 2 |
|
3 | 3 | const _ = require('lodash')
|
4 | 4 | const path = require('path')
|
@@ -600,6 +600,53 @@ describe('the nyc cli', function () {
|
600 | 600 | done()
|
601 | 601 | })
|
602 | 602 | })
|
| 603 | + |
| 604 | + describe('es-modules', function () { |
| 605 | + afterEach(function () { |
| 606 | + rimraf.sync(path.resolve(fixturesCLI, './output')) |
| 607 | + }) |
| 608 | + |
| 609 | + it('instruments file with `package` keyword when es-modules is disabled', function (done) { |
| 610 | + const args = [bin, 'instrument', '--no-es-modules', './not-strict.js', './output'] |
| 611 | + |
| 612 | + const proc = spawn(process.execPath, args, { |
| 613 | + cwd: fixturesCLI, |
| 614 | + env: env |
| 615 | + }) |
| 616 | + |
| 617 | + proc.on('close', function (code) { |
| 618 | + code.should.equal(0) |
| 619 | + const subdirExists = fs.existsSync(path.resolve(fixturesCLI, './output')) |
| 620 | + subdirExists.should.equal(true) |
| 621 | + const files = fs.readdirSync(path.resolve(fixturesCLI, './output')) |
| 622 | + files.should.include('not-strict.js') |
| 623 | + done() |
| 624 | + }) |
| 625 | + }) |
| 626 | + |
| 627 | + it('fails on file with `package` keyword when es-modules is enabled', function (done) { |
| 628 | + const args = [bin, 'instrument', '--exit-on-error', './not-strict.js', './output'] |
| 629 | + |
| 630 | + const proc = spawn(process.execPath, args, { |
| 631 | + cwd: fixturesCLI, |
| 632 | + env: env |
| 633 | + }) |
| 634 | + |
| 635 | + let stderr = '' |
| 636 | + proc.stderr.on('data', function (chunk) { |
| 637 | + stderr += chunk |
| 638 | + }) |
| 639 | + |
| 640 | + proc.on('close', function (code) { |
| 641 | + code.should.equal(1) |
| 642 | + stdoutShouldEqual(stderr, ` |
| 643 | + Failed to instrument ./not-strict.js`) |
| 644 | + const subdirExists = fs.existsSync(path.resolve(fixturesCLI, './output')) |
| 645 | + subdirExists.should.equal(false) |
| 646 | + done() |
| 647 | + }) |
| 648 | + }) |
| 649 | + }) |
603 | 650 | })
|
604 | 651 | })
|
605 | 652 |
|
|
0 commit comments