|
1 |
| -import { parseError, runFilesInContext } from '../../index' |
| 1 | +import { compileFiles, parseError, runFilesInContext } from '../../index' |
2 | 2 | import { mockContext } from '../../mocks/context'
|
3 | 3 | import { Chapter } from '../../types'
|
4 | 4 |
|
@@ -73,3 +73,75 @@ describe('runFilesInContext', () => {
|
73 | 73 | `)
|
74 | 74 | })
|
75 | 75 | })
|
| 76 | + |
| 77 | +describe('compileFiles', () => { |
| 78 | + let context = mockContext(Chapter.SOURCE_4) |
| 79 | + |
| 80 | + beforeEach(() => { |
| 81 | + context = mockContext(Chapter.SOURCE_4) |
| 82 | + }) |
| 83 | + |
| 84 | + it('returns IllegalCharInFilePathError if any file path contains invalid characters', () => { |
| 85 | + const files: Record<string, string> = { |
| 86 | + '/a.js': '1 + 2;', |
| 87 | + '/+-.js': '"hello world";' |
| 88 | + } |
| 89 | + compileFiles(files, '/a.js', context) |
| 90 | + expect(parseError(context.errors)).toMatchInlineSnapshot( |
| 91 | + `"File path '/+-.js' must only contain alphanumeric chars and/or '_', '/', '.', '-'."` |
| 92 | + ) |
| 93 | + }) |
| 94 | + |
| 95 | + it('returns IllegalCharInFilePathError if any file path contains invalid characters - verbose', () => { |
| 96 | + const files: Record<string, string> = { |
| 97 | + '/a.js': '1 + 2;', |
| 98 | + '/+-.js': '"hello world";' |
| 99 | + } |
| 100 | + compileFiles(files, '/a.js', context) |
| 101 | + expect(parseError(context.errors, true)).toMatchInlineSnapshot(` |
| 102 | + "File path '/+-.js' must only contain alphanumeric chars and/or '_', '/', '.', '-'. |
| 103 | + Rename the offending file path to only use valid chars. |
| 104 | + " |
| 105 | + `) |
| 106 | + }) |
| 107 | + |
| 108 | + it('returns ConsecutiveSlashesInFilePathError if any file path contains consecutive slash characters', () => { |
| 109 | + const files: Record<string, string> = { |
| 110 | + '/a.js': '1 + 2;', |
| 111 | + '/dir//dir2/b.js': '"hello world";' |
| 112 | + } |
| 113 | + compileFiles(files, '/a.js', context) |
| 114 | + expect(parseError(context.errors)).toMatchInlineSnapshot( |
| 115 | + `"File path '/dir//dir2/b.js' cannot contain consecutive slashes '//'."` |
| 116 | + ) |
| 117 | + }) |
| 118 | + |
| 119 | + it('returns ConsecutiveSlashesInFilePathError if any file path contains consecutive slash characters - verbose', () => { |
| 120 | + const files: Record<string, string> = { |
| 121 | + '/a.js': '1 + 2;', |
| 122 | + '/dir//dir2/b.js': '"hello world";' |
| 123 | + } |
| 124 | + compileFiles(files, '/a.js', context) |
| 125 | + expect(parseError(context.errors, true)).toMatchInlineSnapshot(` |
| 126 | + "File path '/dir//dir2/b.js' cannot contain consecutive slashes '//'. |
| 127 | + Remove consecutive slashes from the offending file path. |
| 128 | + " |
| 129 | + `) |
| 130 | + }) |
| 131 | + |
| 132 | + it('returns CannotFindModuleError if entrypoint file does not exist', () => { |
| 133 | + const files: Record<string, string> = {} |
| 134 | + compileFiles(files, '/a.js', context) |
| 135 | + expect(parseError(context.errors)).toMatchInlineSnapshot(`"Cannot find module '/a.js'."`) |
| 136 | + }) |
| 137 | + |
| 138 | + it('returns CannotFindModuleError if entrypoint file does not exist - verbose', () => { |
| 139 | + const files: Record<string, string> = {} |
| 140 | + compileFiles(files, '/a.js', context) |
| 141 | + expect(parseError(context.errors, true)).toMatchInlineSnapshot(` |
| 142 | + "Cannot find module '/a.js'. |
| 143 | + Check that the module file path resolves to an existing file. |
| 144 | + " |
| 145 | + `) |
| 146 | + }) |
| 147 | +}) |
0 commit comments