-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve unit tests feedback loop by making them asynchronous (#…
…344)
- Loading branch information
1 parent
e0d70bb
commit fdb0ab2
Showing
21 changed files
with
219 additions
and
357 deletions.
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 |
---|---|---|
@@ -1,58 +1,39 @@ | ||
import pack from './utils/pack'; | ||
|
||
describe('emit error', () => { | ||
it('should not emit errors if emitError is false', (done) => { | ||
it('should not emit errors if emitError is false', async () => { | ||
const compiler = pack('error', { emitError: false }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasErrors()).toBe(false); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
|
||
it('should emit errors if emitError is undefined', (done) => { | ||
it('should emit errors if emitError is undefined', async () => { | ||
const compiler = pack('error'); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasErrors()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasErrors()).toBe(true); | ||
}); | ||
|
||
it('should emit errors if emitError is true', (done) => { | ||
it('should emit errors if emitError is true', async () => { | ||
const compiler = pack('error', { emitError: true }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasErrors()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasErrors()).toBe(true); | ||
}); | ||
|
||
it('should emit errors, but not warnings if emitError is true and emitWarning is false', (done) => { | ||
it('should emit errors, but not warnings if emitError is true and emitWarning is false', async () => { | ||
const compiler = pack('full-of-problems', { | ||
emitError: true, | ||
emitWarning: false, | ||
}); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(true); | ||
}); | ||
|
||
it('should emit errors and warnings if emitError is true and emitWarning is undefined', (done) => { | ||
it('should emit errors and warnings if emitError is true and emitWarning is undefined', async () => { | ||
const compiler = pack('full-of-problems', { emitError: true }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
expect(stats.hasErrors()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
expect(stats.hasErrors()).toBe(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,58 +1,38 @@ | ||
import pack from './utils/pack'; | ||
|
||
describe('emit warning', () => { | ||
it('should not emit warnings if emitWarning is false', (done) => { | ||
it('should not emit warnings if emitWarning is false', async () => { | ||
const compiler = pack('warning', { emitWarning: false }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
}); | ||
|
||
it('should emit warnings if emitWarning is undefined', (done) => { | ||
it('should emit warnings if emitWarning is undefined', async () => { | ||
const compiler = pack('warning'); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
}); | ||
|
||
it('should emit warnings if emitWarning is true', (done) => { | ||
it('should emit warnings if emitWarning is true', async () => { | ||
const compiler = pack('warning', { emitWarning: true }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
}); | ||
|
||
it('should emit warnings, but not warnings if emitWarning is true and emitError is false', (done) => { | ||
it('should emit warnings, but not warnings if emitWarning is true and emitError is false', async () => { | ||
const compiler = pack('full-of-problems', { | ||
emitWarning: true, | ||
emitError: false, | ||
}); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
expect(stats.hasErrors()).toBe(false); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
|
||
it('should emit warnings and errors if emitWarning is true and emitError is undefined', (done) => { | ||
it('should emit warnings and errors if emitWarning is true and emitError is undefined', async () => { | ||
const compiler = pack('full-of-problems', { emitWarning: true }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
expect(stats.hasErrors()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(true); | ||
expect(stats.hasErrors()).toBe(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import { join } from 'path'; | ||
|
||
import webpack from 'webpack'; | ||
|
||
import StylelintWebpackPlugin from '../src'; | ||
|
||
describe('empty', () => { | ||
it('no error when no files matching', (done) => { | ||
const compiler = webpack({ | ||
context: join(__dirname, 'fixtures', 'empty'), | ||
mode: 'development', | ||
entry: './index', | ||
plugins: [new StylelintWebpackPlugin()], | ||
}); | ||
import pack from './utils/pack'; | ||
|
||
compiler.run((err, stats) => { | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
done(); | ||
}); | ||
describe('empty', () => { | ||
it('no error when no files matching', async () => { | ||
const compiler = pack( | ||
'empty', | ||
{}, | ||
{ | ||
plugins: [new StylelintWebpackPlugin()], | ||
}, | ||
); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,36 +1,24 @@ | ||
import pack from './utils/pack'; | ||
|
||
describe('exclude', () => { | ||
it('should exclude with globs', (done) => { | ||
it('should exclude with globs', async () => { | ||
const compiler = pack('exclude', { exclude: ['*test*'] }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
|
||
it('should exclude files', (done) => { | ||
it('should exclude files', async () => { | ||
const compiler = pack('exclude', { exclude: ['test.scss'] }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
|
||
it('should exclude folders', (done) => { | ||
it('should exclude folders', async () => { | ||
const compiler = pack('exclude-folder', { exclude: ['folder'] }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasWarnings()).toBe(false); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,33 +1,22 @@ | ||
import pack from './utils/pack'; | ||
|
||
describe('fail on error', () => { | ||
it('should emits errors', (done) => { | ||
it('should emits errors', async () => { | ||
const compiler = pack('error', { failOnError: true }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasErrors()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasErrors()).toBe(true); | ||
}); | ||
|
||
it('should emit warnings when disabled', (done) => { | ||
it('should emit warnings when disabled', async () => { | ||
const compiler = pack('error', { failOnError: false }); | ||
|
||
compiler.run((err, stats) => { | ||
expect(err).toBeNull(); | ||
expect(stats.hasErrors()).toBe(false); | ||
expect(stats.hasWarnings()).toBe(true); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasErrors()).toBe(false); | ||
expect(stats.hasWarnings()).toBe(true); | ||
}); | ||
|
||
it('should correctly indentifies a success', (done) => { | ||
it('should correctly indentifies a success', async () => { | ||
const compiler = pack('good', { failOnError: true }); | ||
|
||
compiler.run((err) => { | ||
expect(err).toBeNull(); | ||
done(); | ||
}); | ||
const stats = await compiler.runAsync(); | ||
expect(stats.hasErrors()).toBe(false); | ||
}); | ||
}); |
Oops, something went wrong.