-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first class Javascript/Typescript support to the Mill build tool (#…
- Loading branch information
1 parent
0d879c5
commit da37921
Showing
32 changed files
with
606 additions
and
120 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 |
---|---|---|
|
@@ -2,9 +2,9 @@ package build | |
|
||
import mill._, javascriptlib._ | ||
|
||
object foo extends JestModule { | ||
object foo extends TypeScriptModule { | ||
def npmDeps = Seq("[email protected]") | ||
|
||
object test extends TypeScriptTests with TestModule.Jest | ||
} | ||
|
||
// Documentation for mill.example.javascriptlib | ||
|
@@ -15,16 +15,10 @@ Hello James Bond Professor | |
|
||
> mill foo.test | ||
PASS .../foo.test.ts | ||
...generateUser function | ||
...should generate a user with all specified fields... | ||
...should default lastName and role when they are not provided... | ||
...should default all fields when args is empty... | ||
... | ||
Test Suites:...1 passed, 1 total... | ||
Tests:...3 passed, 3 total... | ||
Snapshots:... | ||
Time:... | ||
Ran all test suites matching ... | ||
... | ||
|
||
> mill show foo.bundle | ||
Build succeeded! | ||
|
2 changes: 1 addition & 1 deletion
2
...ptlib/basic/1-simple/foo/test/foo.test.ts → ...sic/1-simple/foo/test/src/foo/foo.test.ts
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
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,13 +1,32 @@ | ||
// @ts-nocheck | ||
import {pathsToModuleNameMapper} from 'node_modules/ts-jest'; | ||
import {compilerOptions} from './tsconfig.json'; // this is a generated file. | ||
|
||
// Remove unwanted keys | ||
const moduleDeps = {...compilerOptions.paths}; | ||
delete moduleDeps['*']; | ||
delete moduleDeps['typeRoots']; | ||
|
||
// moduleNameMapper evaluates in order they appear, | ||
// sortedModuleDeps makes sure more specific path mappings always appear first | ||
const sortedModuleDeps = Object.keys(moduleDeps) | ||
.sort((a, b) => b.length - a.length) // Sort by descending length | ||
.reduce((acc, key) => { | ||
acc[key] = moduleDeps[key]; | ||
return acc; | ||
}, {}); | ||
|
||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: [ | ||
'<rootDir>/**/test/**/*.test.ts', | ||
'<rootDir>/**/test/**/*.test.js', | ||
'<rootDir>/**/**/**/*.test.ts', | ||
'<rootDir>/**/**/**/*.test.js', | ||
], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.json' }], | ||
'^.+\\.(js|jsx)$': 'babel-jest', // Use babel-jest for JS/JSX files | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
moduleNameMapper: pathsToModuleNameMapper(sortedModuleDeps) // use absolute paths generated in tsconfig. | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
...3-custom-build-logic/foo/test/foo.test.ts → ...-build-logic/foo/test/src/foo/foo.test.ts
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
28 changes: 23 additions & 5 deletions
28
example/javascriptlib/basic/3-custom-build-logic/jest.config.ts
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,14 +1,32 @@ | ||
// @ts-nocheck | ||
import {pathsToModuleNameMapper} from 'node_modules/ts-jest'; | ||
import {compilerOptions} from './tsconfig.json'; // this is a generated file. | ||
|
||
// Remove unwanted keys | ||
const moduleDeps = {...compilerOptions.paths}; | ||
delete moduleDeps['*']; | ||
delete moduleDeps['typeRoots']; | ||
|
||
// moduleNameMapper evaluates in order they appear, | ||
// sortedModuleDeps makes sure more specific path mappings always appear first | ||
const sortedModuleDeps = Object.keys(moduleDeps) | ||
.sort((a, b) => b.length - a.length) // Sort by descending length | ||
.reduce((acc, key) => { | ||
acc[key] = moduleDeps[key]; | ||
return acc; | ||
}, {}); | ||
|
||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: [ | ||
'<rootDir>/**/test/**/*.test.ts', | ||
'<rootDir>/**/test/**/*.test.js', | ||
'<rootDir>/**/**/**/*.test.ts', | ||
'<rootDir>/**/**/**/*.test.js', | ||
], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': ['ts-jest', {tsconfig: 'tsconfig.json'}], | ||
'^.+\\.(js|jsx)$': 'babel-jest', | ||
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.json' }], | ||
'^.+\\.(js|jsx)$': 'babel-jest', // Use babel-jest for JS/JSX files | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
moduleNameMapper: {} | ||
moduleNameMapper: pathsToModuleNameMapper(sortedModuleDeps) // use absolute paths generated in tsconfig. | ||
}; |
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
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
2 changes: 1 addition & 1 deletion
2
...asic/4-multi-modules/qux/test/qux.test.ts → ...ulti-modules/qux/test/src/qux/qux.test.ts
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
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
25 changes: 22 additions & 3 deletions
25
example/javascriptlib/basic/5-client-server-hello/jest.config.ts
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,13 +1,32 @@ | ||
// @ts-nocheck | ||
import {pathsToModuleNameMapper} from 'node_modules/ts-jest'; | ||
import {compilerOptions} from './tsconfig.json'; // this is a generated file. | ||
|
||
// Remove unwanted keys | ||
const moduleDeps = {...compilerOptions.paths}; | ||
delete moduleDeps['*']; | ||
delete moduleDeps['typeRoots']; | ||
|
||
// moduleNameMapper evaluates in order they appear, | ||
// sortedModuleDeps makes sure more specific path mappings always appear first | ||
const sortedModuleDeps = Object.keys(moduleDeps) | ||
.sort((a, b) => b.length - a.length) // Sort by descending length | ||
.reduce((acc, key) => { | ||
acc[key] = moduleDeps[key]; | ||
return acc; | ||
}, {}); | ||
|
||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: [ | ||
'<rootDir>/**/test/**/*.test.ts', | ||
'<rootDir>/**/test/**/*.test.js', | ||
'<rootDir>/**/**/**/*.test.ts', | ||
'<rootDir>/**/**/**/*.test.js', | ||
], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': ['ts-jest', {tsconfig: 'tsconfig.json'}], | ||
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.json' }], | ||
'^.+\\.(js|jsx)$': 'babel-jest', // Use babel-jest for JS/JSX files | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
moduleNameMapper: pathsToModuleNameMapper(sortedModuleDeps) // use absolute paths generated in tsconfig. | ||
}; |
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
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
27 changes: 23 additions & 4 deletions
27
example/javascriptlib/basic/6-client-server-realistic/server/jest.config.ts
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,13 +1,32 @@ | ||
// @ts-nocheck | ||
import {pathsToModuleNameMapper} from 'node_modules/ts-jest'; | ||
import {compilerOptions} from './tsconfig.json'; // this is a generated file. | ||
|
||
// Remove unwanted keys | ||
const moduleDeps = {...compilerOptions.paths}; | ||
delete moduleDeps['*']; | ||
delete moduleDeps['typeRoots']; | ||
|
||
// moduleNameMapper evaluates in order they appear, | ||
// sortedModuleDeps makes sure more specific path mappings always appear first | ||
const sortedModuleDeps = Object.keys(moduleDeps) | ||
.sort((a, b) => b.length - a.length) // Sort by descending length | ||
.reduce((acc, key) => { | ||
acc[key] = moduleDeps[key]; | ||
return acc; | ||
}, {}); | ||
|
||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: [ | ||
'<rootDir>/**/test/**/*.test.ts', | ||
'<rootDir>/**/test/**/*.test.js', | ||
'<rootDir>/**/**/**/*.test.ts', | ||
'<rootDir>/**/**/**/*.test.js', | ||
], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': ['ts-jest', {tsconfig: 'tsconfig.json'}], | ||
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.json' }], | ||
'^.+\\.(js|jsx)$': 'babel-jest', // Use babel-jest for JS/JSX files | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
moduleNameMapper: pathsToModuleNameMapper(sortedModuleDeps) // use absolute paths generated in tsconfig. | ||
}; |
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
12 changes: 12 additions & 0 deletions
12
example/javascriptlib/testing/1-test-suite/bar/src/calculator.ts
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,12 @@ | ||
export class Calculator { | ||
add(a: number, b: number): number { | ||
return a + b; | ||
} | ||
|
||
divide(a: number, b: number): number { | ||
if (b === 0) { | ||
throw new Error("Division by zero is not allowed"); | ||
} | ||
return a / b; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
example/javascriptlib/testing/1-test-suite/bar/test/src/bar/calculator.test.ts
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,28 @@ | ||
import {Calculator} from 'bar/calculator'; | ||
|
||
describe('Calculator', () => { | ||
const calculator = new Calculator(); | ||
|
||
describe('Addition', () => { | ||
test('should return the sum of two numbers', () => { | ||
const result = calculator.add(2, 3); | ||
expect(result).toEqual(5); | ||
}); | ||
|
||
test('should return the correct sum for negative numbers', () => { | ||
const result = calculator.add(-2, -3); | ||
expect(result).toEqual(-5); | ||
}); | ||
}); | ||
|
||
describe('Division', () => { | ||
test('should return the quotient of two numbers', () => { | ||
const result = calculator.divide(6, 3); | ||
expect(result).toEqual(2); | ||
}); | ||
|
||
it('should throw an error when dividing by zero', () => { | ||
expect(() => calculator.divide(6, 0)).toThrow("Division by zero is not allowed"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.