Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
191586d2
Commit
191586d2
authored
Jan 12, 2026
by
Brooke Mosby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update validation
parent
d22acf0d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
1 deletion
+94
-1
generate-deployment-id.test.ts
test/unit/generate-deployment-id.test.ts
+94
-1
No files found.
test/unit/generate-deployment-id.test.ts
View file @
191586d2
import
{
generateDeploymentId
}
from
'next/dist/build/generate-deployment-id'
import
{
generateDeploymentId
,
resolveAndSetDeploymentId
,
}
from
'next/dist/build/generate-deployment-id'
describe
(
'generateDeploymentId'
,
()
=>
{
it
(
'should return undefined when deploymentId is undefined'
,
()
=>
{
...
...
@@ -37,3 +40,93 @@ describe('generateDeploymentId', () => {
expect
(
generateDeploymentId
(
' '
)).
toBe
(
' '
)
})
})
describe
(
'resolveAndSetDeploymentId'
,
()
=>
{
beforeEach
(()
=>
{
delete
process
.
env
.
NEXT_DEPLOYMENT_ID
})
afterEach
(()
=>
{
delete
process
.
env
.
NEXT_DEPLOYMENT_ID
})
it
(
'should reject deploymentId with invalid characters (spaces)'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my deployment id'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should reject deploymentId with invalid characters (question mark)'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my-deployment?id=123'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should reject deploymentId with invalid characters (ampersand)'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my-deployment&id=123'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should reject deploymentId with invalid characters (percent)'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my-deployment%20id'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should reject deploymentId with invalid characters (slash)'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my/deployment/id'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should reject deploymentId with invalid characters (dot)'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my.deployment.id'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should reject deploymentId with control characters'
,
()
=>
{
expect
(()
=>
resolveAndSetDeploymentId
(
'my-deployment
\
tid'
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should allow deploymentId with valid characters (base62 + hyphen + underscore)'
,
()
=>
{
const
result
=
resolveAndSetDeploymentId
(
'my-deployment_v2-abc123XYZ'
)
expect
(
result
).
toBe
(
'my-deployment_v2-abc123XYZ'
)
expect
(
process
.
env
.
NEXT_DEPLOYMENT_ID
).
toBe
(
'my-deployment_v2-abc123XYZ'
)
})
it
(
'should allow deploymentId with only alphanumeric characters'
,
()
=>
{
const
result
=
resolveAndSetDeploymentId
(
'abc123XYZ789'
)
expect
(
result
).
toBe
(
'abc123XYZ789'
)
expect
(
process
.
env
.
NEXT_DEPLOYMENT_ID
).
toBe
(
'abc123XYZ789'
)
})
it
(
'should allow deploymentId with only hyphens'
,
()
=>
{
const
result
=
resolveAndSetDeploymentId
(
'---'
)
expect
(
result
).
toBe
(
'---'
)
expect
(
process
.
env
.
NEXT_DEPLOYMENT_ID
).
toBe
(
'---'
)
})
it
(
'should allow deploymentId with only underscores'
,
()
=>
{
const
result
=
resolveAndSetDeploymentId
(
'___'
)
expect
(
result
).
toBe
(
'___'
)
expect
(
process
.
env
.
NEXT_DEPLOYMENT_ID
).
toBe
(
'___'
)
})
it
(
'should reject deploymentId from function that returns invalid characters'
,
()
=>
{
const
fn
=
()
=>
'my deployment id'
expect
(()
=>
resolveAndSetDeploymentId
(
fn
)).
toThrow
(
'contains invalid characters'
)
})
it
(
'should allow deploymentId from function that returns valid characters'
,
()
=>
{
const
fn
=
()
=>
'my-deployment_v2-abc123XYZ'
const
result
=
resolveAndSetDeploymentId
(
fn
)
expect
(
result
).
toBe
(
'my-deployment_v2-abc123XYZ'
)
expect
(
process
.
env
.
NEXT_DEPLOYMENT_ID
).
toBe
(
'my-deployment_v2-abc123XYZ'
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment