forked from EndemolShineGroup/cosmiconfig-typescript-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include `cosmiconfig` APIs to perform testing fix EndemolShineGroup#134
- Loading branch information
Showing
6 changed files
with
112 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Example } from './success' | ||
|
||
const errorExample: Example = { | ||
foo: 1 | ||
} | ||
|
||
export default errorExample |
This file was deleted.
Oops, something went wrong.
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,3 +1,9 @@ | ||
export default { | ||
foo: 'bar', | ||
}; | ||
export interface Example { | ||
foo: string | ||
} | ||
|
||
const example: Example = { | ||
foo: 'bar' | ||
} | ||
|
||
export default example; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const errorAttributeNoValue = { | ||
foo:, | ||
} | ||
|
||
export default errorAttributeNoValue; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
interface TestConfig { | ||
foo: string | ||
} | ||
|
||
const test: TestConfig = { | ||
foo: 'bar' | ||
} | ||
|
||
export default test |
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,22 +1,91 @@ | ||
import path from 'path'; | ||
import { cosmiconfig, cosmiconfigSync } from 'cosmiconfig'; | ||
|
||
import loader from '.'; | ||
import TypeScriptCompileError from './Errors/TypeScriptCompileError'; | ||
|
||
const FIXTURES_PATH = path.resolve(__dirname, '__fixtures__'); | ||
|
||
describe('TypeScriptLoader', () => { | ||
it('compiles a valid TypeScript file', async () => { | ||
const result = await loader(path.resolve(FIXTURES_PATH, 'success'), ''); | ||
expect(result).toEqual({ foo: 'bar' }); | ||
}); | ||
|
||
it('fails to compile an invalid TypeScript file', async () => { | ||
try { | ||
await loader(path.resolve(FIXTURES_PATH, 'error'), ''); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(TypeScriptCompileError); | ||
expect(error.toObject().message).toMatch('Failed to compile TypeScript'); | ||
} | ||
}); | ||
describe('via cosmiconfig API', () => { | ||
it('compiles a valid TypeScript file', async () => { | ||
try { | ||
const test = await cosmiconfig('test-success', { | ||
loaders: { | ||
'.ts': loader() | ||
} | ||
}).load(path.resolve(FIXTURES_PATH, 'test-success.config.ts')) | ||
expect(test?.config).toEqual({ foo: 'bar' }); | ||
} catch (error) { | ||
throw error | ||
} | ||
}); | ||
|
||
it('fails to compile an invalid TypeScript file because no value inside object', async () => { | ||
try { | ||
const test = await cosmiconfig('test-error', { | ||
loaders: { | ||
'.ts': loader() | ||
} | ||
}).load(path.resolve(FIXTURES_PATH, 'test-error.config.ts')) | ||
expect(test?.config).toEqual({ foo: 'bar' }); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(TypeScriptCompileError); | ||
expect(error.toObject().message).toMatch('Failed to compile TypeScript'); | ||
} | ||
}); | ||
|
||
it('fails to compile an invalid TypeScript file because interface mismatch', async () => { | ||
try { | ||
const test = await cosmiconfig('error-interface-mismatch', { | ||
loaders: { | ||
'.ts': loader() | ||
} | ||
}).load(path.resolve(FIXTURES_PATH, 'error-interface-mismatch.config.ts')) | ||
expect(test?.config).toEqual({ foo: 'bar' }); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(TypeScriptCompileError); | ||
expect(error.toObject().message).toMatch('Failed to compile TypeScript'); | ||
} | ||
}); | ||
}) | ||
|
||
describe('via cosmiconfigSync API', () => { | ||
it('compiles a valid TypeScript file', () => { | ||
const test = cosmiconfigSync('test-success', { | ||
loaders: { | ||
'.ts': loader() | ||
} | ||
}).load(path.resolve(FIXTURES_PATH, 'test-success.config.ts')) | ||
expect(test?.config).toEqual({ foo: 'bar' }); | ||
}); | ||
|
||
it('fails to compile an invalid TypeScript file because no value inside object', () => { | ||
try { | ||
const test = cosmiconfigSync('test-error', { | ||
loaders: { | ||
'.ts': loader() | ||
} | ||
}).load(path.resolve(FIXTURES_PATH, 'test-error.config.ts')) | ||
expect(test?.config).toEqual({ foo: 'bar' }); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(TypeScriptCompileError); | ||
expect(error.toObject().message).toMatch('Failed to compile TypeScript'); | ||
} | ||
}); | ||
|
||
it('fails to compile an invalid TypeScript file because interface mismatch', () => { | ||
try { | ||
const test = cosmiconfigSync('error-interface-mismatch', { | ||
loaders: { | ||
'.ts': loader() | ||
} | ||
}).load(path.resolve(FIXTURES_PATH, 'error-interface-mismatch.config.ts')) | ||
expect(test?.config).toEqual({ foo: 'bar' }); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(TypeScriptCompileError); | ||
expect(error.toObject().message).toMatch('Failed to compile TypeScript'); | ||
} | ||
}); | ||
}) | ||
}); |