From 172da462b9c09ea9c8f34de1a79dffbd34194684 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 4 Nov 2020 20:36:02 +0530 Subject: [PATCH] tests: add a case for invalid context value (#2030) --- test/core-flags/context-flag.test.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/core-flags/context-flag.test.js b/test/core-flags/context-flag.test.js index 98f13ea2c24..f725b129d00 100644 --- a/test/core-flags/context-flag.test.js +++ b/test/core-flags/context-flag.test.js @@ -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'`); }); });