-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(functions): add firebase-json tests, fix other tests
- Loading branch information
Showing
9 changed files
with
76 additions
and
23 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transformIgnorePatterns: ['^.+\\.js$'], | ||
testMatch: ['**.spec.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {readFileSync} from 'fs'; | ||
import {minimatch} from 'minimatch'; | ||
|
||
describe('firebase.json', () => { | ||
const filePath = '../firebase.json'; | ||
let fileContent: string; | ||
|
||
beforeEach(() => { | ||
fileContent = readFileSync(filePath, 'utf8'); | ||
}); | ||
|
||
// Prevent mistakes like - https://github.com/sign/translate/commit/ad0ef31a0a2b3cd989dff6a9dcec742157d9619d | ||
it('firebase.json should be a valid JSON file', async () => { | ||
expect(JSON.parse(fileContent)).toBeTruthy(); | ||
}); | ||
|
||
it('firebase.json should have rewrites', async () => { | ||
const obj = JSON.parse(fileContent); | ||
expect(obj.hosting.rewrites).toBeTruthy(); | ||
}); | ||
|
||
function resolveRewrite(path: string) { | ||
const rewrites = JSON.parse(fileContent).hosting.rewrites; | ||
|
||
for (const rewrite of rewrites) { | ||
if (minimatch(path, rewrite.source)) { | ||
return rewrite.function ?? rewrite.destination; | ||
} | ||
} | ||
return path; | ||
} | ||
|
||
it('firebase.json should redirect "/random-path" to the index.html', async () => { | ||
expect(resolveRewrite('/random-path')).toEqual('/index.html'); | ||
}); | ||
|
||
it('firebase.json should not redirect assets to the index.html', async () => { | ||
// Fixed in https://github.com/sign/translate/commit/730546444bf1a35c2097230b1562783ae0dfda2a | ||
// If even a single i18n asset is redirected instead of 404 error, Transloco reverts everything to English | ||
expect(resolveRewrite('/assets/random-path')).toEqual('/assets/random-path'); | ||
}); | ||
}); |
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
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
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