Skip to content

Commit f6fcf3d

Browse files
committed
build(ui-alerts,console): make documentation preview builds show console logs
INSTUI-4522
1 parent f5941b1 commit f6fcf3d

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.github/workflows/preview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
- name: Build docs-app
2525
run: npm run build:docs
2626
if: github.event.action != 'closed'
27+
env:
28+
GITHUB_PULL_REQUEST_PREVIEW: 'true'
2729
- uses: rossjrw/pr-preview-action@v1
2830
with:
2931
source-dir: ./packages/__docs__/__build__

packages/__docs__/webpack.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import { globbySync } from 'globby'
3030
import { merge } from 'webpack-merge'
3131
import { processSingleFile } from './lib/build-docs.mjs'
3232
import resolve from './resolve.mjs'
33+
import webpack from 'webpack'
3334

3435
const ENV = process.env.NODE_ENV || 'production'
3536
const DEBUG = process.env.DEBUG || ENV === 'development'
37+
const GITHUB_PULL_REQUEST_PREVIEW = process.env.GITHUB_PULL_REQUEST_PREVIEW || 'false'
3638

3739
const outputPath = resolvePath(import.meta.dirname, '__build__')
3840
const resolveAliases = DEBUG ? { resolve } : {}
@@ -79,6 +81,9 @@ const config = merge(baseConfig, {
7981
template: './src/index.html',
8082
chunks: ['main'],
8183
}),
84+
new webpack.DefinePlugin({
85+
'process.env.GITHUB_PULL_REQUEST_PREVIEW': JSON.stringify(GITHUB_PULL_REQUEST_PREVIEW),
86+
}),
8287
],
8388
optimization: {
8489
usedExports: true,

packages/console/src/console.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ function logMessage(
5555
message: string,
5656
...args: unknown[]
5757
) {
58-
if (process.env.NODE_ENV !== 'production' && !condition) {
58+
if (
59+
(process.env.GITHUB_PULL_REQUEST_PREVIEW ||
60+
process.env.NODE_ENV !== 'production') &&
61+
!condition
62+
) {
5963
if (typeof console[level] === 'function') {
6064
const renderStack = withRenderStack ? getRenderStack() : ''
6165
//@ts-expect-error level can be 'constructor' which is not callable

packages/ui-alerts/src/Alert/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ class Alert extends Component<AlertProps, AlertState> {
308308
}
309309

310310
render() {
311+
// Test 1: Check if the code path exists
312+
// eslint-disable-next-line no-console
313+
console.log('TEST: This line should always appear')
314+
315+
// Test 2: Check if conditional code exists
316+
if (process.env.NODE_ENV !== 'production') {
317+
// eslint-disable-next-line no-console
318+
console.log('TEST: This should only appear in development')
319+
}
320+
321+
// Test 3: Force the condition to be runtime-evaluated
322+
if (process.env.GITHUB_PULL_REQUEST_PREVIEW) {
323+
// eslint-disable-next-line no-console
324+
console.log('TEST: Runtime evaluation')
325+
}
311326
const liveRegion = this.getLiveRegion()
312327
const screenReaderContent = liveRegion
313328
? this.createScreenReaderPortal(liveRegion)

0 commit comments

Comments
 (0)