Skip to content

Commit 38232a2

Browse files
committed
[issue-9] added action and end to end tests
1 parent 7725fc9 commit 38232a2

File tree

6 files changed

+133
-4
lines changed

6 files changed

+133
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: End To End Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
12+
jobs:
13+
NPM-E2E-Test:
14+
runs-on: ubuntu-latest
15+
container:
16+
image: snakepy/node:node18-latest
17+
environment: test
18+
steps:
19+
- name: Check out repository code
20+
uses: actions/checkout@v4
21+
- run: npm install
22+
- run: npm run build
23+
- run: npm link
24+
- name: "Setup repository"
25+
run: |
26+
cd ../
27+
git config --global user.email ${{ secrets.GIT_EMAIL }}
28+
git config --global user.name ${{ secrets.GIT_USER }}
29+
git clone https://github.com/snake-py/eject-test.git
30+
cd eject-test
31+
git checkout npm
32+
npm install
33+
git add -A
34+
git stash
35+
npx eject react --verbose
36+
- name: "Run E2E Test"
37+
run: npm run test:e2e:base --dependency="react" --dpath="../eject-test" --dmanager="npm"
38+
39+
PNPM-E2E-Test:
40+
runs-on: ubuntu-latest
41+
container:
42+
image: snakepy/node:node18-latest
43+
environment: test
44+
steps:
45+
- name: Check out repository code
46+
uses: actions/checkout@v4
47+
- run: npm install
48+
- run: npm run build
49+
- run: npm link
50+
- name: "Setup repository"
51+
run: |
52+
cd ../
53+
git config --global user.email ${{ secrets.GIT_EMAIL }}
54+
git config --global user.name ${{ secrets.GIT_USER }}
55+
git clone https://github.com/snake-py/eject-test.git
56+
cd eject-test
57+
git checkout pnpm
58+
pnpm install
59+
git add -A
60+
git stash
61+
npx eject react --verbose
62+
- name: "Run E2E Base Test"
63+
run: npm run test:e2e:base --dependency="react" --dpath="../eject-test" --dmanager="pnpm"
64+
- name: "Run E2E PNPM Test"
65+
run: npm run test:e2e:pnpm --dependency="react" --dpath="../eject-test" --dmanager="pnpm"

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"release": "release-me patch",
1717
"release:minor": "release-me minor",
1818
"release:major": "release-me major",
19-
"release:commit": "release-me commit"
19+
"release:commit": "release-me commit",
20+
"test:e2e:base": "node ./tests/e2e/base.js $npm_config_dependency $npm_config_dpath $npm_config_dmanager",
21+
"test:e2e:pnpm": "node ./tests/e2e/pnpm.js $npm_config_dependency $npm_config_dpath $npm_config_dmanager"
2022
},
2123
"repository": {
2224
"type": "git",
@@ -47,4 +49,4 @@
4749
"eject": "./bin-entry.js",
4850
"ejectjs": "./bin-entry.js"
4951
}
50-
}
52+
}

src/command.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export function eject(
1919
dependency: string,
2020
options: { force: boolean; verbose: boolean },
2121
) {
22+
if (options.verbose) {
23+
console.log({
24+
dependency,
25+
options,
26+
isCI: process.env.GITHUB_ACTIONS,
27+
});
28+
}
29+
2230
if (!options.force && !isGitInstalled()) {
2331
warnLog(
2432
'Git is not installed, please install git or use --force to bypass git check',
@@ -38,21 +46,25 @@ export function eject(
3846
} catch (error) {
3947
if (options.verbose) {
4048
errorLog('Error ejecting dependency:', dependency);
49+
console.error(error);
4150
}
4251
}
4352

4453
if (successfulEjected) {
4554
console.log('✅ Ejected dependencies:', chalk.bold(dependency));
4655
} else {
4756
console.log('❌ Ejected dependencies: ', chalk.bold(dependency));
48-
return;
57+
return 150;
4958
}
5059
const { packageManager, lockFile } = detectPackageManager();
5160
updatePackageJson(dependency, packageManager === 'pnpm' ? 'link' : 'file');
5261
commitEjection(config.COMMIT_MESSAGE);
5362
const needsToCommit = dependencyManagerAction(packageManager);
5463
if (needsToCommit) amendCommit();
55-
const installCmd = `${packageManager} install`;
64+
let installCmd = `${packageManager} install`;
65+
if (process.env.GITHUB_ACTIONS && packageManager === 'pnpm') {
66+
installCmd = 'pnpm install --no-frozen-lockfile';
67+
}
5668
const installLog = chalk.bold(installCmd);
5769
console.log(`📦 Running ${installLog} to update ${chalk.bold(lockFile)}`);
5870
execSync(installCmd, { stdio: 'inherit' });

tests/e2e/base.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// read command line arguments
2+
import assert from 'assert';
3+
import fs from 'fs';
4+
import { resolve } from 'path';
5+
const args = process.argv.slice(2);
6+
const dependency = args[0];
7+
const testProjectPath = args[1];
8+
const dependencyManager = args[2] ?? 'npm';
9+
10+
assert(fs.existsSync(testProjectPath), 'testProjectPath does not exist');
11+
assert(
12+
fs.existsSync(resolve(testProjectPath, 'ejected')),
13+
'No ejected folder found',
14+
);
15+
assert(
16+
fs.existsSync(resolve(testProjectPath, 'ejected', dependency)),
17+
'No ejection found for dependency',
18+
);
19+
20+
const packageJson = JSON.parse(
21+
fs.readFileSync(resolve(testProjectPath, 'package.json'), 'utf8'),
22+
);
23+
24+
assert(
25+
packageJson.dependencies[dependency].includes(
26+
dependencyManager === 'pnpm'
27+
? 'link:./ejected/' + dependency
28+
: 'file:./ejected/' + dependency,
29+
),
30+
'Dependency is not properly ejected',
31+
);

tests/e2e/pnpm.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// read command line arguments
2+
import assert from 'assert';
3+
import fs from 'fs';
4+
import { resolve } from 'path';
5+
import { parse } from 'yaml';
6+
7+
const args = process.argv.slice(2);
8+
const dependency = args[0];
9+
const testProjectPath = args[1];
10+
11+
assert(
12+
fs.existsSync(resolve(testProjectPath, 'pnpm-workspace.yaml')),
13+
'pnpm-workspace.yaml does not exist',
14+
);
15+
const workspace = parse(
16+
fs.readFileSync(resolve(testProjectPath, 'pnpm-workspace.yaml'), 'utf-8'),
17+
);
18+
console.log(workspace);
19+
assert(workspace.packages.includes(`ejected/*`), 'No ejected workspace found');
File renamed without changes.

0 commit comments

Comments
 (0)