-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 1498 #1118
Merged
Merged
Issue 1498 #1118
Changes from 11 commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
f7e3efd
Add getLastObservedReleaseId
PiotrKozlowski ec416a2
Pull out writing file logic from createRedirects.ts
PiotrKozlowski 92a3fb3
Redirect on locationChange if url was found in the redirects.json file
PiotrKozlowski 8f78cd4
Add support for developments version fo redirects json
PiotrKozlowski d1daf32
Create prepareRedirects function from createRedirects
PiotrKozlowski 26483c0
It is not working yet, but I am commiting so I can go back to this
PiotrKozlowski 2edd83b
revert changes
PiotrKozlowski dcdd608
new way of handling redirects
PiotrKozlowski 086e9af
Add tests
PiotrKozlowski 4f93e12
Merge branch 'master' into issue-1498
staxly[bot] f23a6bd
Merge branch 'master' into issue-1498
staxly[bot] 8164541
Merge branch 'master' into issue-1498
staxly[bot] f995b1c
Merge branch 'master' into issue-1498
staxly[bot] d474031
Merge branch 'master' into issue-1498
staxly[bot] 7c9343b
Pull out writing file logic from createRedirects.ts
PiotrKozlowski 7b285a7
Create prepareRedirects function from createRedirects
PiotrKozlowski dd6c9f3
Merge branch 'master' into issue-1498
staxly[bot] ac5691d
Create redirects on the fly
PiotrKozlowski 0773fc8
move prepareRedirects to scripts folder
PiotrKozlowski 58433ee
Merge branch 'issue-1498' of github.com:openstax/rex-web into issue-1498
PiotrKozlowski 18fcdf0
dont forget about required presets and plugins
PiotrKozlowski 3067341
Try increasing file watchers
PiotrKozlowski 2573771
share babel config
PiotrKozlowski c929e90
Revert "Try increasing file watchers"
PiotrKozlowski ea1d61a
Merge branch 'master' into issue-1498
staxly[bot] fdf33ca
Merge branch 'master' into issue-1498
staxly[bot] 2bf14b8
Merge branch 'master' into issue-1498
staxly[bot] 896e141
Move prepareRedirects outside of the middleware
PiotrKozlowski 662a2d2
mock implementation for history replace
PiotrKozlowski a4b070d
increase number of watches
PiotrKozlowski c33c9f7
try without sudo
PiotrKozlowski cfdd282
remove command for increasing file watches
PiotrKozlowski 6207ee0
Check if this helps
PiotrKozlowski 90d9a24
Check if requiring babel config twice breaks something
PiotrKozlowski dda6d81
Does requiring more stuff cause error
PiotrKozlowski 6987549
What if i import only prepareRedirects?
PiotrKozlowski 08812ab
Uncomment everything in setupProxy - error is caused by prepareRedire…
PiotrKozlowski 242ed7e
Instead of reading all files in data/redirects/, read list off books …
PiotrKozlowski 04b6102
Revert "Instead of reading all files in data/redirects/, read list of…
PiotrKozlowski d638bdd
mock prepareRedirects to check if it is really realted to this function
PiotrKozlowski 145e960
Revert "mock prepareRedirects to check if it is really realted to thi…
PiotrKozlowski 431821c
What if we require only createArchiveLoader
PiotrKozlowski c7641a1
And what about importing only createOSWebLoader
PiotrKozlowski 6f9f55c
Uncomment import of prepareRedirects
PiotrKozlowski c2d4905
change prepareRedirects to always return []
PiotrKozlowski 67a5a2c
Revert "change prepareRedirects to always return []"
PiotrKozlowski 253212a
Instead of reading all files in data/redirects/, read list off books …
PiotrKozlowski c04d565
Revert "Instead of reading all files in data/redirects/, read list of…
PiotrKozlowski aaec10a
Check if this is about dynamic imports
PiotrKozlowski 569cbf9
Check if importing content route is breaking something
PiotrKozlowski 97c258a
Run only Test CI job
PiotrKozlowski f95969a
remove whole for loop from preprareRedirects
PiotrKozlowski 8dc8e96
setup job is still required
PiotrKozlowski 7f7939b
Check if removing makeUnifiedBookLoader from prepareRedirects will help
PiotrKozlowski bf6fcc0
Reset to commit 662a2d2a4bc20f6517dd807639423c0259dcfc1f
PiotrKozlowski 9c6aaa2
narrow ci to run only test and setup jobs
PiotrKozlowski 76fb01f
Remove stripIdVersion from createArchiveLoader
PiotrKozlowski 157ea27
Import only createArchiveLoader
PiotrKozlowski 94aa04c
Import only createArchiveLoader
PiotrKozlowski 0eacff5
Import also prepareRedirects
PiotrKozlowski 1a8167d
remove makeUnifiedBookLoader from prepareRedirects
PiotrKozlowski 6dbd19b
remove findArchiveTreeNodeById from prepareRedirects
PiotrKozlowski a9f32f5
use stripIdVersion in createArchiveLoader again
PiotrKozlowski 2bcdc41
Import stripIdVersion from idUtils
PiotrKozlowski 31a5265
i didnt want to import findArchiveTreeNodeById in prepareRedirects
PiotrKozlowski 1eadfc8
import only prepareRedirects
PiotrKozlowski 5a6c0b2
Display max_user_watches limit on gh
PiotrKozlowski 8b9d863
Add modulePathIgnorePatterns to jest config
PiotrKozlowski 6b6f95f
Revert "Add modulePathIgnorePatterns to jest config"
PiotrKozlowski cdec20c
Try adding watchmanconfig - jest uses it by default
PiotrKozlowski a8e044a
Try adding hint_num_dirs to watchmanconfig
PiotrKozlowski 0928d1e
Reset to 662a2d2a4bc20f6517dd807639423c0259dcfc1f
PiotrKozlowski ae3e384
remove watchmanconfig
PiotrKozlowski 71b2964
Dont remove util module even if it is not used
PiotrKozlowski 1837aa3
Merge branch 'master' into issue-1498
staxly[bot] 40b16e3
Add sysctls settings to test job container
PiotrKozlowski a227145
rearange sysctls option
PiotrKozlowski 093afae
nest sysctls in options
PiotrKozlowski 1918fd1
try other syntax
PiotrKozlowski ad02fa6
one more try
PiotrKozlowski 9bc0cf3
try adding privileged to the options
PiotrKozlowski 2467324
add alowed-unsafe-sysctls
PiotrKozlowski fb8b57f
revert ci.yml
PiotrKozlowski fdc7bd8
Add --watchAll=false flag to test:unit
PiotrKozlowski 79e527f
Revert "Add --watchAll=false flag to test:unit"
PiotrKozlowski aea0b2c
remove -i flag from test:browser
PiotrKozlowski d744b00
Revert "remove -i flag from test:browser"
PiotrKozlowski 411fadd
add logs to check what is triggering inotify
PiotrKozlowski 8d6b5ea
Revert "add logs to check what is triggering inotify"
PiotrKozlowski 5abc7e9
jest watchman: false
PiotrKozlowski f143acf
Revert "jest watchman: false"
PiotrKozlowski 083ea95
Add SKIP_PREFLIGHT_CHECK=true SERVER_MODE=built to test:unit and set …
PiotrKozlowski dfffea3
Leave only SERVER_MODE=built and add it to test:browser
PiotrKozlowski 6eb465c
just use yarn server instead of yarn start in jest-puppeteer.config.js
PiotrKozlowski 7d8fa6f
Add and configure cracto to fix inotify limit issue
PiotrKozlowski a4d32b0
Use another config for test:unit
PiotrKozlowski a28c1b3
Run test:browser after test:unit/build is finished
PiotrKozlowski 9682270
Remove default jest preset and use it in commands
PiotrKozlowski 639489f
move browser job to matrix again
PiotrKozlowski 8a1058d
make sure that craco options that wasnt working locally does not work…
PiotrKozlowski 9e6e92a
Ignore all files
PiotrKozlowski de18be1
Ignore only node_modules files
PiotrKozlowski 9b6fe4a
Remove craco and do not test:browser in ci
PiotrKozlowski 15c2fee
test:screenshots should use jest-puppeteer preset
PiotrKozlowski 32dd6a2
Merge branch 'master' into issue-1498
staxly[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 +1,2 @@ | ||
export type Redirects = Array<{ bookId: string, pageId: string, pathname: string }>; | ||
export type RedirectsData = Array<{ bookId: string, pageId: string, pathname: string }>; | ||
export type Redirects = Array<{ from: string, to: string }>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import createTestServices from '../../../test/createTestServices'; | ||
import createTestStore from '../../../test/createTestStore'; | ||
import { MiddlewareAPI, Store } from '../../types'; | ||
import { receivePageNotFoundId } from '../actions'; | ||
|
||
const mockFetch = (valueToReturn: any, error?: any) => () => new Promise((resolve, reject) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
resolve({ json: () => new Promise((res) => res(valueToReturn)) }); | ||
}); | ||
|
||
describe('receivePageNotFoundId hook', () => { | ||
let hook: ReturnType<typeof import ('./receivePageNotFoundId').receivePageNotFoundIdHookBody>; | ||
let store: Store; | ||
let helpers: MiddlewareAPI & ReturnType<typeof createTestServices>; | ||
let historyReplaceSpy: jest.SpyInstance; | ||
let fetchBackup: any; | ||
|
||
beforeEach(() => { | ||
store = createTestStore(); | ||
|
||
helpers = { | ||
...createTestServices(), | ||
dispatch: store.dispatch, | ||
getState: store.getState, | ||
}; | ||
|
||
helpers.history.location = { | ||
pathname: '/books/physics/pages/1-introduction301', | ||
} as any; | ||
|
||
historyReplaceSpy = jest.spyOn(helpers.history, 'replace'); | ||
|
||
fetchBackup = (globalThis as any).fetch; | ||
|
||
hook = require('./receivePageNotFoundId').receivePageNotFoundIdHookBody(helpers); | ||
}); | ||
|
||
afterEach(() => { | ||
(globalThis as any).fetch = fetchBackup; | ||
}); | ||
|
||
it('checks for redirects when receivePageNotFoundId is dispatched and noops if path wasn\'t found', async() => { | ||
(globalThis as any).fetch = mockFetch([{ from: 'asd', to: 'asd' }]); | ||
|
||
await hook(receivePageNotFoundId('asdf')); | ||
|
||
expect(historyReplaceSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('noops if fetch fails', async() => { | ||
(globalThis as any).fetch = mockFetch(undefined, 'error'); | ||
|
||
await hook(receivePageNotFoundId('asdf')); | ||
|
||
expect(historyReplaceSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls history.replace if redirect is found', async() => { | ||
(globalThis as any).fetch = mockFetch([{ from: helpers.history.location.pathname, to: 'redirected' }]); | ||
|
||
await hook(receivePageNotFoundId('asdf')); | ||
|
||
expect(historyReplaceSpy).toHaveBeenCalledWith('redirected'); | ||
}); | ||
}); |
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,21 @@ | ||
import { Redirects } from '../../../../data/redirects/types'; | ||
import { ActionHookBody } from '../../types'; | ||
import { actionHook } from '../../utils'; | ||
import { receivePageNotFoundId } from '../actions'; | ||
|
||
export const receivePageNotFoundIdHookBody: ActionHookBody<typeof receivePageNotFoundId> = ( | ||
services | ||
) => async() => { | ||
const redirects: Redirects = await fetch('/rex/redirects.json') | ||
.then((res) => res.json()) | ||
.catch(() => []); | ||
|
||
for (const {from, to} of redirects) { | ||
if (from === services.history.location.pathname) { | ||
services.history.replace(to); | ||
return; | ||
} | ||
} | ||
}; | ||
|
||
export default actionHook(receivePageNotFoundId, receivePageNotFoundIdHookBody); |
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,3 @@ | ||
[ | ||
{ "from": "/books/physics/pages/1-introduction301", "to": "/books/physics/pages/1-introduction" } | ||
] |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try throwing a
mockImplementation
on this, i wonder if the history implementation is causing issues for youThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it didn't help, i'll keep trying