-
-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70ba799
commit f3d0310
Showing
6 changed files
with
140 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,4 @@ test/**/**/binary/** | |
test/**/dist | ||
test/**/**/dist | ||
test/**/**/**/dist | ||
test/**/stats.json |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
const { run } = require('../utils/test-utils'); | ||
const { stat, readFile } = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
describe('warnings', () => { | ||
it('should output by default', () => { | ||
const { stdout, exitCode } = run(__dirname); | ||
|
||
expect(stdout).toMatch(/ERROR in/); | ||
expect(stdout).toMatch(/Error: Can't resolve/); | ||
expect(exitCode).toBe(1); | ||
}); | ||
|
||
it('should output JSON with the "json" flag', () => { | ||
const { stdout, exitCode } = run(__dirname, ['--json']); | ||
|
||
expect(() => JSON.parse(stdout)).not.toThrow(); | ||
expect(exitCode).toBe(1); | ||
|
||
const json = JSON.parse(stdout); | ||
|
||
expect(json['hash']).toBeDefined(); | ||
expect(json['errorsCount']).toBe(1); | ||
expect(json['errors'][0].message).toMatch(/Can't resolve/); | ||
}); | ||
|
||
it('should store json to a file', (done) => { | ||
const { stdout, exitCode } = run(__dirname, ['--json', 'stats.json']); | ||
|
||
expect(stdout).toContain('stats are successfully stored as json to stats.json'); | ||
expect(exitCode).toBe(1); | ||
|
||
stat(resolve(__dirname, './stats.json'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
|
||
readFile(resolve(__dirname, 'stats.json'), 'utf-8', (error, data) => { | ||
expect(error).toBe(null); | ||
expect(() => JSON.parse(data)).not.toThrow(); | ||
|
||
const json = JSON.parse(data); | ||
|
||
expect(json['hash']).toBeDefined(); | ||
expect(json['errorsCount']).toBe(1); | ||
expect(json['errors'][0].message).toMatch(/Can't resolve/); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import unknown from './unknown.mjs'; | ||
|
||
export default unknown |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let module; | ||
|
||
try { | ||
module = require('unknown'); | ||
} catch (e) { | ||
// Ignore | ||
} | ||
|
||
export default module |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
const { run } = require('../utils/test-utils'); | ||
const { stat, readFile } = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
describe('errors', () => { | ||
it('should output by default', () => { | ||
const { stdout, exitCode } = run(__dirname); | ||
|
||
expect(stdout).toMatch(/WARNING in/); | ||
expect(stdout).toMatch(/Error: Can't resolve/); | ||
expect(exitCode).toBe(0); | ||
}); | ||
|
||
it('should output JSON with the "json" flag', () => { | ||
const { stdout, exitCode } = run(__dirname, ['--json']); | ||
|
||
expect(() => JSON.parse(stdout)).not.toThrow(); | ||
expect(exitCode).toBe(0); | ||
|
||
const json = JSON.parse(stdout); | ||
|
||
expect(json['hash']).toBeDefined(); | ||
expect(json['warningsCount']).toBe(1); | ||
expect(json['warnings'][0].message).toMatch(/Can't resolve/); | ||
}); | ||
|
||
it('should store json to a file', (done) => { | ||
const { stdout, exitCode } = run(__dirname, ['--json', 'stats.json']); | ||
|
||
expect(stdout).toContain('stats are successfully stored as json to stats.json'); | ||
expect(exitCode).toBe(0); | ||
|
||
stat(resolve(__dirname, './stats.json'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
|
||
readFile(resolve(__dirname, 'stats.json'), 'utf-8', (error, data) => { | ||
expect(error).toBe(null); | ||
expect(() => JSON.parse(data)).not.toThrow(); | ||
|
||
const json = JSON.parse(data); | ||
|
||
expect(json['hash']).toBeDefined(); | ||
expect(json['warningsCount']).toBe(1); | ||
expect(json['warnings'][0].message).toMatch(/Can't resolve/); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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