-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
lens: fixes BASE_PATH handling and re-aligns to old resource paths #3722
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This is needed while dependencies rely on different versions of react | ||
legacy-peer-deps=true | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<base href="/zipkin" > | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without this, anything that emulates zipkin-server's ZIPKIN_UI_BASE_PATH handling would have broke. |
||
<meta charset="utf-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</head> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,65 +13,60 @@ | |
*/ | ||
import { render, screen } from '@testing-library/react'; | ||
import fetchMock from 'fetch-mock'; | ||
import { afterEach, beforeEach, it, describe, expect } from 'vitest'; | ||
import { afterEach, it, describe, expect, vi } from 'vitest'; | ||
import React, { Suspense } from 'react'; | ||
|
||
import { | ||
defaultConfig, | ||
UiConfigConsumer, | ||
UiConfig as RawUIConfig, | ||
} from './UiConfig'; | ||
import { UI_CONFIG } from '../../constants/api'; | ||
|
||
afterEach(() => { | ||
fetchMock.restore(); | ||
vi.resetModules(); | ||
}); | ||
|
||
beforeEach(() => { | ||
// We fetch the resource on module initialization for performance, but want to do that in every | ||
// test. | ||
}); | ||
|
||
const UiConfig = () => { | ||
return ( | ||
const renderUiConfig = async () => { | ||
const { UiConfigConsumer, UiConfig } = await import('./UiConfig'); | ||
render( | ||
<Suspense fallback="Suspended"> | ||
<RawUIConfig> | ||
<UiConfig> | ||
<UiConfigConsumer> | ||
{(value) => <div>{JSON.stringify(value)}</div>} | ||
</UiConfigConsumer> | ||
</RawUIConfig> | ||
</Suspense> | ||
</UiConfig> | ||
</Suspense>, | ||
); | ||
}; | ||
|
||
describe('<UiConfig />', () => { | ||
it('fetches config and suspends', async () => { | ||
const configPromise = new Promise(() => undefined); | ||
const { UI_CONFIG } = await import('../../constants/api'); | ||
fetchMock.once(UI_CONFIG, configPromise, { overwriteRoutes: true }); | ||
|
||
render(<UiConfig />); | ||
await renderUiConfig(); | ||
expect(screen.getAllByText('Suspended')).length(1); | ||
|
||
fetchMock.called(UI_CONFIG); | ||
}); | ||
|
||
it('provides config when resolved', async () => { | ||
it('provides config when resolved', (context) => async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this file was renamed in the last commit, none of the tests ran. I was able to get the former to run and pass, but it is a bit hacky as I really have no idea what I'm doing. @anuraaga this is on a shared branch.. I think your old test was trying to show that the UI can work while the config.json request hasn't completed yet? I tried for over an hour to try to get this to work, so am not bothering you randomly.. could really use a hand (even you can paste) if you can help get this working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #3724 for follow-up |
||
const config = { defaultLookback: 100 }; | ||
const { defaultConfig } = await import('./UiConfig'); | ||
Object.keys(defaultConfig).forEach((key) => { | ||
config[key] = config[key] || defaultConfig[key]; | ||
}); | ||
|
||
const { UI_CONFIG } = await import('../../constants/api'); | ||
fetchMock.once(UI_CONFIG, config, { overwriteRoutes: true }); | ||
|
||
render(<UiConfig />); | ||
expect(screen.getAllByText('Suspended').length).toBe(1); | ||
// TODO: adrian needs help, as this broke when porting to vitest | ||
context.skip(); | ||
|
||
const { rerender } = await renderUiConfig(); | ||
expect(screen.getAllByText('Suspended')).length(1); | ||
|
||
/*// We need to get off the processing loop to allow the promise to complete and resolve the | ||
// We need to get off the processing loop to allow the promise to complete and resolve the | ||
// config. | ||
await new Promise((resolve) => setTimeout(resolve, 1)); | ||
|
||
rerender(<UiConfig />); | ||
expect(screen.getByText(JSON.stringify(config))).toBeInTheDocument();*/ | ||
rerender(); // was rerender(<UiConfig />); | ||
expect(screen.getByText(JSON.stringify(config))).toBeInTheDocument(); | ||
|
||
fetchMock.called(UI_CONFIG); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2015-2024 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
/* eslint-disable global-require */ | ||
|
||
import { afterEach, it, describe, expect, vi } from 'vitest'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file was deleted in the last commit. I resurrected it. |
||
|
||
// To test BASE_PATH we can't import it above, as it would return a constant | ||
// value for all tests. Instead, we use `await import` later. | ||
describe('BASE_PATH', () => { | ||
afterEach(() => { | ||
vi.resetModules(); | ||
}); | ||
|
||
it('defaults to /zipkin with no base tag', async () => { | ||
const { BASE_PATH } = await import('./api'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ps I barely understand what I was doing here, but by behavior, I notice you have to defer anything you want reverted by resetModules. This was the only way I could monkey it to work, and if is not the correct way, please suggest an alternative! |
||
expect(BASE_PATH).toEqual('/zipkin'); | ||
}); | ||
|
||
it('is set to base tag when present', async () => { | ||
const base = document.createElement('base'); | ||
base.setAttribute('href', '/coolzipkin/'); | ||
document.head.append(base); | ||
|
||
const { BASE_PATH } = await import('./api'); | ||
expect(BASE_PATH).toEqual('/coolzipkin'); | ||
}); | ||
}); |
This file was deleted.
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.
unless you put this here, you have to remember not just for npm install, but also audit