-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for self-importing packages (#68070)
I've simplified @timneutkens's tests from #66486 The resolver fix is in vercel/turborepo#8820 Closes #66486 Related issue: #66487 --------- Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
- Loading branch information
1 parent
9568a4f
commit b564855
Showing
18 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/self-importing-package-monorepo/app/layout.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
test/e2e/app-dir/self-importing-package-monorepo/app/page.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'index' |
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/self-importing-package-monorepo/internal-pkg/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/self-importing-package-monorepo/internal-pkg/src/env.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const env = 'test' |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/self-importing-package-monorepo/internal-pkg/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
6
test/e2e/app-dir/self-importing-package-monorepo/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
test/e2e/app-dir/self-importing-package-monorepo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/e2e/app-dir/self-importing-package-monorepo/self-importing-package-monorepo.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
test/e2e/app-dir/self-importing-package/internal-pkg/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/self-importing-package/internal-pkg/src/env.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const env = 'test' |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/self-importing-package/internal-pkg/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { env } from 'internal-pkg/env' | ||
|
||
export default `${env} abc` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"my-package": "file:./my-package.tar" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/e2e/app-dir/self-importing-package/self-importing-package.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |