Skip to content
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

feat: show progress while waiting for framework server to start #4683

Merged
merged 24 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
75c4c4f
feat: show progress while waiting for framework server to start
ericapisani Jun 8, 2022
5905455
chore: update contributors field
ericapisani Jun 8, 2022
032c953
chore: update contributors field
token-generator-app[bot] Jun 8, 2022
dfd5b81
test: update snapshot tests
ericapisani Jun 10, 2022
98a43f9
Merge branch 'main' into ep/show-progress-while-waiting-for-framework…
ericapisani Jun 10, 2022
0ed3945
chore: update contributors field
ericapisani Jun 10, 2022
bc92821
chore: update contributors field
token-generator-app[bot] Jun 10, 2022
3c10491
style: run prettier
ericapisani Jun 10, 2022
4800ef9
Merge branch 'ep/show-progress-while-waiting-for-framework-to-startup…
ericapisani Jun 10, 2022
99e6082
chore: update contributors field
ericapisani Jun 10, 2022
6460f35
chore: update contributors field
token-generator-app[bot] Jun 10, 2022
79c07c2
test: add regex to remove extra dots that lead to flaky snapshots
ericapisani Jun 10, 2022
2ce0523
Merge branch 'ep/show-progress-while-waiting-for-framework-to-startup…
ericapisani Jun 10, 2022
52c1edc
chore: update contributors field
ericapisani Jun 10, 2022
fc5bcad
chore: update contributors field
token-generator-app[bot] Jun 10, 2022
3497c30
test: move normalizer into the framework test suite
ericapisani Jun 10, 2022
a00dc1a
Merge branch 'ep/show-progress-while-waiting-for-framework-to-startup…
ericapisani Jun 10, 2022
a4c5a7d
chore: update contributors field
ericapisani Jun 10, 2022
136a1c1
Merge branch 'main' into ep/show-progress-while-waiting-for-framework…
ericapisani Jun 10, 2022
ba2f5dd
test: silly mistake
ericapisani Jun 10, 2022
4699f96
Merge branch 'ep/show-progress-while-waiting-for-framework-to-startup…
ericapisani Jun 10, 2022
c47224f
style: lint
ericapisani Jun 10, 2022
6bb3d10
test: update other tests to use the other normalizer func
ericapisani Jun 10, 2022
892df97
Merge branch 'main' into ep/show-progress-while-waiting-for-framework…
ericapisani Jun 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Eduardo Bouças <[email protected]> (https://twitter.com/eduardoboucas)",
"Emily Zhang (https://twitter.com/mlylzhng)",
"Erez Rokah (https://www.erezro.com)",
"Erica Pisani <[email protected]>",
"Evans Hauser (https://twitter.com/evanshauser)",
"Finn Woelm (https://twitter.com/FinnWoelm)",
"Flxbot",
Expand Down
5 changes: 4 additions & 1 deletion src/commands/dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ const startFrameworkServer = async function ({ settings }) {
runCommand(settings.command, settings.env)

try {
log(
`${NETLIFYDEVLOG} Waiting for framework port ${settings.frameworkPort}. This can be configured using the 'targetPort' property in the netlify.toml`,
)
const open = await waitPort({
port: settings.frameworkPort,
output: 'silent',
output: 'dots',
timeout: FRAMEWORK_PORT_TIMEOUT,
...(settings.pollingStrategies.includes('HTTP') && { protocol: 'http' }),
})
Expand Down
37 changes: 20 additions & 17 deletions tests/integration/600.framework-detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const { normalize } = require('./utils/snapshots')

const content = 'Hello World!'

// Remove extra '.'s resulting from different load times which lead to flaky snapshots
const frameworkDetectionNormalizer = (output) => normalize(output.replace(/\.+(?=\.)/, ''))

const test = isCI ? avaTest.serial.bind(avaTest) : avaTest

test('should default to process.cwd() and static server', async (t) => {
Expand All @@ -27,7 +30,7 @@ test('should default to process.cwd() and static server', async (t) => {
const response = await got(url).text()
t.is(response, content)

t.snapshot(normalize(output))
t.snapshot(frameworkDetectionNormalizer(output))
})
})
})
Expand All @@ -45,7 +48,7 @@ test('should use static server when --dir flag is passed', async (t) => {
const response = await got(url).text()
t.is(response, content)

t.snapshot(normalize(output))
t.snapshot(frameworkDetectionNormalizer(output))
})
})
})
Expand All @@ -64,7 +67,7 @@ test('should use static server when framework is set to #static', async (t) => {
const response = await got(url).text()
t.is(response, content)

t.snapshot(normalize(output))
t.snapshot(frameworkDetectionNormalizer(output))
})
})
})
Expand All @@ -84,7 +87,7 @@ test('should log the command if using static server and `command` is configured'
const response = await got(url).text()
t.is(response, content)

t.snapshot(normalize(output))
t.snapshot(frameworkDetectionNormalizer(output))
},
)
})
Expand All @@ -105,7 +108,7 @@ test('should warn if using static server and `targetPort` is configured', async
const response = await got(url).text()
t.is(response, content)

t.snapshot(normalize(output))
t.snapshot(frameworkDetectionNormalizer(output))
},
)
})
Expand All @@ -123,7 +126,7 @@ test('should run `command` when both `command` and `targetPort` are configured',
true,
),
)
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -133,7 +136,7 @@ test('should force a specific framework when configured', async (t) => {

// a failure is expected since this is not a true create-react-app project
const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true))
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -142,7 +145,7 @@ test('should throw when forcing a non supported framework', async (t) => {
await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync()

const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true))
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -156,7 +159,7 @@ test('should detect a known framework', async (t) => {

// a failure is expected since this is not a true create-react-app project
const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true))
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -167,7 +170,7 @@ test('should throw if framework=#custom but command is missing', async (t) => {
const error = await t.throwsAsync(() =>
withDevServer({ cwd: builder.directory, args: ['--targetPort', '3000'] }, () => {}, true),
)
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -178,7 +181,7 @@ test('should throw if framework=#custom but targetPort is missing', async (t) =>
const error = await t.throwsAsync(() =>
withDevServer({ cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true),
)
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -193,7 +196,7 @@ test('should start custom command if framework=#custom, command and targetPort a
true,
),
)
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -218,7 +221,7 @@ test(`should print specific error when command doesn't exist`, async (t) => {
true,
),
)
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand Down Expand Up @@ -247,7 +250,7 @@ test('should prompt when multiple frameworks are detected', async (t) => {

await childProcess
})
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -263,7 +266,7 @@ test('should not run framework detection if command and targetPort are configure
true,
),
)
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand All @@ -283,7 +286,7 @@ test('should filter frameworks with no dev command', async (t) => {
const response = await got(url).text()
t.is(response, content)

t.snapshot(normalize(output))
t.snapshot(frameworkDetectionNormalizer(output))
})
})
})
Expand All @@ -302,7 +305,7 @@ test('should pass framework-info env to framework sub process', async (t) => {

// a failure is expected since this is not a true Gatsby project
const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true))
t.snapshot(normalize(error.stdout))
t.snapshot(frameworkDetectionNormalizer(error.stdout))
})
})

Expand Down
26 changes: 17 additions & 9 deletions tests/integration/snapshots/600.framework-detection.test.js.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Snapshot report for `tests/600.framework-detection.test.js`
# Snapshot report for `tests/integration/600.framework-detection.test.js`

The actual snapshot is saved in `600.framework-detection.test.js.snap`.

Expand Down Expand Up @@ -108,7 +108,8 @@ Generated by [AVA](https://avajs.dev).

`◈ Netlify Dev ◈␊
◈ Starting Netlify Dev with custom config␊
hello␊
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.hello␊
◈ "echo hello" exited with code *. Shutting down Netlify Dev server`

## should force a specific framework when configured
Expand All @@ -117,7 +118,8 @@ Generated by [AVA](https://avajs.dev).

`◈ Netlify Dev ◈␊
◈ Starting Netlify Dev with Create React App␊
◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists`
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists`

## should throw when forcing a non supported framework

Expand All @@ -132,7 +134,8 @@ Generated by [AVA](https://avajs.dev).

`◈ Netlify Dev ◈␊
◈ Starting Netlify Dev with Create React App␊
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.␊
> start␊
> react-scripts start␊
Expand All @@ -158,7 +161,8 @@ Generated by [AVA](https://avajs.dev).

`◈ Netlify Dev ◈␊
◈ Starting Netlify Dev with #custom␊
hello␊
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.hello␊
◈ "echo hello" exited with code *. Shutting down Netlify Dev server`

## should print specific error when command doesn't exist
Expand All @@ -170,7 +174,8 @@ Generated by [AVA](https://avajs.dev).
◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊
◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊
◈ Starting Netlify Dev with #custom␊
◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists`
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists`

## should prompt when multiple frameworks are detected

Expand All @@ -184,7 +189,8 @@ Generated by [AVA](https://avajs.dev).
> [Create React App] 'npm run start' ? Multiple possible start commands found Create React App-npm run start␊
Add 'framework = "create-react-app"' to the [dev] section of your netlify.toml to avoid this selection prompt next time␊
◈ Starting Netlify Dev with Create React App␊
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.␊
> start␊
> react-scripts start␊
Expand All @@ -199,7 +205,8 @@ Generated by [AVA](https://avajs.dev).
◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊
◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊
◈ Starting Netlify Dev with custom config␊
hello␊
◈ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:3000.hello␊
◈ "echo hello" exited with code *. Shutting down Netlify Dev server`

## should filter frameworks with no dev command
Expand Down Expand Up @@ -229,7 +236,8 @@ Generated by [AVA](https://avajs.dev).

`◈ Netlify Dev ◈␊
◈ Starting Netlify Dev with Gatsby␊
◈ Waiting for framework port 8000. This can be configured using the 'targetPort' property in the netlify.toml␊
Waiting for localhost:8000.␊
> develop␊
> node -p process.env.GATSBY_LOGGER␊
Expand Down
Binary file not shown.