|
9 | 9 |
|
10 | 10 | 'use strict'; |
11 | 11 |
|
| 12 | +const os = require('os'); |
12 | 13 | const chai = require('chai'); |
13 | 14 | chai.use(require('chai-fs')); |
14 | 15 | const expect = chai.expect; |
@@ -1721,6 +1722,73 @@ module.exports = { |
1721 | 1722 | }, true); |
1722 | 1723 | }); |
1723 | 1724 |
|
| 1725 | + it('When enabled, eslint checks for linting errors by using configuration from file', (done) => { |
| 1726 | + const cwd = process.cwd(); |
| 1727 | + after(() => { |
| 1728 | + process.chdir(cwd); |
| 1729 | + }); |
| 1730 | + |
| 1731 | + const appDir = testSetup.createTestAppDir(); |
| 1732 | + const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev'); |
| 1733 | + config.setPublicPath('/build'); |
| 1734 | + config.addEntry('main', './js/eslint-es2018'); |
| 1735 | + config.enableEslintLoader({ |
| 1736 | + // Force eslint-loader to output errors instead of sometimes |
| 1737 | + // using warnings (see: https://github.com/MoOx/eslint-loader#errors-and-warning) |
| 1738 | + emitError: true, |
| 1739 | + }); |
| 1740 | + fs.writeFileSync( |
| 1741 | + path.join(appDir, '.eslintrc.js'), |
| 1742 | + ` |
| 1743 | +module.exports = { |
| 1744 | + parser: 'babel-eslint', |
| 1745 | + rules: { |
| 1746 | + 'indent': ['error', 2], |
| 1747 | + 'no-unused-vars': ['error', { 'args': 'all' }] |
| 1748 | + } |
| 1749 | +} ` |
| 1750 | + ); |
| 1751 | + |
| 1752 | + process.chdir(appDir); |
| 1753 | + |
| 1754 | + testSetup.runWebpack(config, (webpackAssert, stats) => { |
| 1755 | + const eslintErrors = stats.toJson().errors[0]; |
| 1756 | + |
| 1757 | + expect(eslintErrors).not.to.contain('Parsing error: Unexpected token ..'); |
| 1758 | + expect(eslintErrors).to.contain('Expected indentation of 0 spaces but found 2'); |
| 1759 | + expect(eslintErrors).to.contain('\'x\' is assigned a value but never used'); |
| 1760 | + expect(eslintErrors).to.contain('\'b\' is assigned a value but never used'); |
| 1761 | + |
| 1762 | + done(); |
| 1763 | + }, true); |
| 1764 | + }); |
| 1765 | + |
| 1766 | + it('When enabled and without any configuration, ESLint will throw an error and a nice message should be displayed', (done) => { |
| 1767 | + const cwd = process.cwd(); |
| 1768 | + |
| 1769 | + this.timeout(5000); |
| 1770 | + setTimeout(() => { |
| 1771 | + process.chdir(cwd); |
| 1772 | + done(); |
| 1773 | + }, 4000); |
| 1774 | + |
| 1775 | + const appDir = testSetup.createTestAppDir(os.tmpdir()); // to prevent issue with Encore's .eslintrc.js |
| 1776 | + const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev'); |
| 1777 | + config.setPublicPath('/build'); |
| 1778 | + config.addEntry('main', './js/eslint'); |
| 1779 | + config.enableEslintLoader({ |
| 1780 | + // Force eslint-loader to output errors instead of sometimes |
| 1781 | + // using warnings (see: https://github.com/MoOx/eslint-loader#errors-and-warning) |
| 1782 | + emitError: true, |
| 1783 | + }); |
| 1784 | + |
| 1785 | + process.chdir(appDir); |
| 1786 | + |
| 1787 | + expect(() => { |
| 1788 | + testSetup.runWebpack(config, (webpackAssert, stats) => {}); |
| 1789 | + }).to.throw('No ESLint configration has been found.'); |
| 1790 | + }); |
| 1791 | + |
1724 | 1792 | it('Code splitting with dynamic import', (done) => { |
1725 | 1793 | const config = createWebpackConfig('www/build', 'dev'); |
1726 | 1794 | config.setPublicPath('/build'); |
|
0 commit comments