-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add a case for invalid context value (#2030)
- Loading branch information
Showing
1 changed file
with
18 additions
and
3 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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
const { resolve } = require('path'); | ||
const { run, isWindows } = require('../utils/test-utils'); | ||
|
||
describe('--context flag', () => { | ||
it('should allow to set context', () => { | ||
const { stderr, stdout } = run(__dirname, ['--context', '/test-context-path']); | ||
const { stderr, stdout, exitCode } = run(__dirname, ['--context', './']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('test-context-path'); | ||
expect(exitCode).toBe(0); | ||
if (isWindows) { | ||
const windowsPath = resolve(__dirname, './').replace(/\\/g, '\\\\'); | ||
expect(stdout).toContain(`context: '${windowsPath}'`); | ||
} else { | ||
expect(stdout).toContain(`context: '${resolve(__dirname, './')}'`); | ||
} | ||
}); | ||
|
||
it('should throw module not found error for invalid context', () => { | ||
const { stderr, stdout, exitCode } = run(__dirname, ['--context', '/invalid-context-path']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(exitCode).toBe(1); | ||
expect(stdout).toContain(`Module not found: Error: Can't resolve './src/main.js'`); | ||
}); | ||
}); |