Skip to content

Commit

Permalink
tests: add a case for invalid context value (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Nov 4, 2020
1 parent ec6d8b3 commit 172da46
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions test/core-flags/context-flag.test.js
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'`);
});
});

0 comments on commit 172da46

Please sign in to comment.