|
| 1 | +const fixWinOsPathSep = require(`../src/fixWinOsPathSep`); |
| 2 | +const loader = require('../src/index.js'); |
| 3 | + |
| 4 | +const mockContext = { |
| 5 | + loader: { |
| 6 | + _module: { |
| 7 | + NormalModule: { |
| 8 | + issuer: { |
| 9 | + ContextModule: { |
| 10 | + debugId: 36, |
| 11 | + regExp: /\.js$/, |
| 12 | + } |
| 13 | + } |
| 14 | + } |
| 15 | + } |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +function cutSpaces(str) { |
| 20 | + return str.replace(/[\s\n\r\t]*/g, ''); |
| 21 | +} |
| 22 | + |
| 23 | +describe('Test winOs (roughly)', () => { |
| 24 | + it('fixWinOsPathSep should do its job correctly', () => { |
| 25 | + expect(fixWinOsPathSep('/path/to/project')).toBe('/path/to/project') |
| 26 | + expect(fixWinOsPathSep('\\path\\to\\project')).toBe('/path/to/project') |
| 27 | + expect(fixWinOsPathSep('C:\\path\\to\\project')).toBe('C:/path/to/project') |
| 28 | + }) |
| 29 | + |
| 30 | + it('Final query should not contain query options', () => { |
| 31 | + function errorHandler(e) { |
| 32 | + throw e; |
| 33 | + } |
| 34 | + const context = { |
| 35 | + ...mockContext, |
| 36 | + query: { |
| 37 | + data: { |
| 38 | + loader: 'babel-loader', |
| 39 | + options: { |
| 40 | + output: 'C:\\root\\the_folder_name_should_not_be_fixed' |
| 41 | + } |
| 42 | + } |
| 43 | + }, |
| 44 | + resourcePath: './index.js', |
| 45 | + emitError: errorHandler |
| 46 | + } |
| 47 | + const result = loader.pitch.call( |
| 48 | + context |
| 49 | + ) |
| 50 | + expect(cutSpaces(result).includes('the_folder_name_should_not_be_fixed')).toBe(false); |
| 51 | + }) |
| 52 | + |
| 53 | + it('Windows-style separators should be replaced, but inline query options does not', () => { |
| 54 | + function errorHandler(e) { |
| 55 | + throw e; |
| 56 | + } |
| 57 | + const context = { |
| 58 | + ...mockContext, |
| 59 | + query: { |
| 60 | + data: 'babel-loader?saveto=C:\\root\\the_folder_name_should_not_be_fixed' |
| 61 | + }, |
| 62 | + resourcePath: './index.js', |
| 63 | + emitError: errorHandler |
| 64 | + } |
| 65 | + const result = loader.pitch.call( |
| 66 | + context |
| 67 | + ) |
| 68 | + expect(cutSpaces(result)).toBe(`module.exports={};module.exports["data"]=require('!babel-loader?saveto=C:\\root\\the_folder_name_should_not_be_fixed!./index.js');`); |
| 69 | + }) |
| 70 | +}); |
0 commit comments