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

Add tests for self-importing packages #68070

Merged
merged 18 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/self-importing-package-monorepo/app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import value from 'internal-pkg'
import localValue from 'next-app'

export default function Home() {
return (
<h1>
Hello world {value} {localValue}
</h1>
)
}
1 change: 1 addition & 0 deletions test/e2e/app-dir/self-importing-package-monorepo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'index'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "internal-pkg",
"private": true,
"type": "module",
"exports": {
".": {
"default": "./src/index.js"
},
"./env": {
"default": "./src/env.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const env = 'test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { env } from 'internal-pkg/env'

export default `${env} abc`
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
19 changes: 19 additions & 0 deletions test/e2e/app-dir/self-importing-package-monorepo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "next-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"internal-pkg": "link:./internal-pkg"
},
"exports": {
".": {
"default": "./index.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { nextTestSetup } from 'e2e-utils'

describe('self-importing-package-monorepo', () => {
const dependencies = (global as any).isNextDeploy
? // `link` is incompatible with the npm version used when this test is deployed
{
'internal-pkg': 'file:./internal-pkg',
}
: {
'internal-pkg': 'link:./internal-pkg',
}
const { next } = nextTestSetup({
files: __dirname,
dependencies,
packageJson: {
name: 'next-app',
exports: {
'.': {
default: './index.js',
},
},
},
})

it('should resolve self-imports inside a monorepo', async () => {
const $ = await next.render$('/')
expect($('h1').text()).toBe('Hello world test abc index')
})
})
7 changes: 7 additions & 0 deletions test/e2e/app-dir/self-importing-package/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/self-importing-package/app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import myMessage from 'internal-pkg'

export default function Page() {
return <h1>{myMessage}</h1>
}
Binary file not shown.
13 changes: 13 additions & 0 deletions test/e2e/app-dir/self-importing-package/internal-pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "internal-pkg",
"private": true,
"type": "module",
"exports": {
".": {
"default": "./src/index.js"
},
"./env": {
"default": "./src/env.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const env = 'test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { env } from 'internal-pkg/env'

export default `${env} abc`
6 changes: 6 additions & 0 deletions test/e2e/app-dir/self-importing-package/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
6 changes: 6 additions & 0 deletions test/e2e/app-dir/self-importing-package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"my-package": "file:./my-package.tar"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { nextTestSetup } from 'e2e-utils'
import path from 'path'

describe('self-importing-package', () => {
const { next } = nextTestSetup({
files: __dirname,
// This test is skipped when deployed because the local tarball appears corrupted
// It also doesn't seem particularly useful to test when deployed
skipDeployment: true,
dependencies: {
'internal-pkg': `file:${path.join(__dirname, 'internal-pkg.tar')}`,
},
})

it('should resolve self-imports in an external package', async () => {
const $ = await next.render$('/')
expect($('h1').text()).toBe('test abc')
})
})
Loading