-
Notifications
You must be signed in to change notification settings - Fork 61
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
test: Package Manager Support for deploy #869
Changes from 19 commits
bd0ef45
247e17b
52d0f6a
c4be31e
2be6ae7
d3e936f
67e7382
2e343ef
e83b172
8bed4d7
339c4e5
e1c22c0
214681d
3d15a4d
ba1ee8b
41803e6
c1f12e6
c52a65b
7ff5e9e
2d798e3
436bb17
5744032
7aadedd
20f72ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.log | ||
logs | ||
coverage | ||
docs | ||
lib | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { existsSync } from 'fs'; | ||
import fs from 'fs/promises'; | ||
import { fileURLToPath } from 'url'; | ||
import fsp from 'fs/promises'; | ||
import path from 'path'; | ||
import * as os from 'os'; | ||
|
||
/** | ||
* Root test directory. | ||
*/ | ||
export const rootTestDir = fileURLToPath( | ||
new URL('./e2e-tests', import.meta.url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the test dir from the repo to a tmpDir so that it's a fresh new project |
||
); | ||
export const rootTestDir = path.join(os.tmpdir(), 'e2e-tests'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to say that I like when test project appear somewhere repo root (like it was before here). Perhaps common ground could be to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw. If we decide to follow suggestion to bootstrap test projects using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm confused. Did you suggest to create the test folder inside our outside of the repo root? The reason why I changed it to a tmpDir was because if it's in the repo root, it shares the node_modules with the repo, which might hide some potential issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized later that if we want to "install" or use "create amplify" then it might be better to have test projects outside of repo root because of what you mentioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we decide to use the repo root and share the node_modules, we should be able to remove the install commands in this PR. Also, we may not need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm in favor of leaving test dirs within the repo root and not doing the extra installation bits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on the other hand we should figure out what we want to test. |
||
|
||
/** | ||
* Creates a test directory. | ||
*/ | ||
export const createTestDirectory = async (pathName: string | URL) => { | ||
if (!existsSync(pathName)) { | ||
await fs.mkdir(pathName, { recursive: true }); | ||
await fsp.mkdir(pathName, { recursive: true }); | ||
} | ||
}; | ||
|
||
|
@@ -23,6 +22,6 @@ export const createTestDirectory = async (pathName: string | URL) => { | |
*/ | ||
export const deleteTestDirectory = async (pathName: string | URL) => { | ||
if (existsSync(pathName)) { | ||
await fs.rm(pathName, { recursive: true, force: true }); | ||
await fsp.rm(pathName, { recursive: true, force: true }); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,11 +115,6 @@ void describe('create-amplify script', { concurrency: concurrency }, () => { | |
); | ||
}); | ||
|
||
after(async () => { | ||
// stop the npm proxy | ||
await execa('npm', ['run', 'stop:npm-proxy'], { stdio: 'inherit' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't stop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deploy.test.ts shouldn't depend on setup from create_amplify. Each test suite should handle it's own setup and teardown. If the setup and teardown of two different test suites conflicts with each other, then we either need to run those suites serially, or figure out some other strategy for doing the setup without introducing coupling between tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I'm thinking if we should publish locally in the GH workflow for all the e2e tests. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about this problem before when I was working on initial version of canary tests and I wanted to include them in normal e2e test run too. I ended up not solving this because canaries never got included in normal e2e tests. What we need here is to develop component that manages npm-proxy lifecycle using OS primitives or file system. The reason for this that npm test runner runs each test file as separate Node process.
I think this piece alone deserves separate PR (which we could do on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other option to solve this particular problem is to wrap node test runner cli with custom script and use programmatic api https://nodejs.org/api/test.html#runoptions . This should allow adding "before/after all test suites" logic. The advantage is that we don't have to implement cross process synchronization logic. |
||
}); | ||
|
||
const initialStates = ['empty', 'module', 'commonjs'] as const; | ||
|
||
initialStates.forEach((initialState) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import fsp from 'fs/promises'; | ||
import path from 'path'; | ||
import { execa } from 'execa'; | ||
import { cdkCli } from '../../process-controller/process_controller.js'; | ||
import { existsSync } from 'fs'; | ||
|
||
|
@@ -24,5 +25,10 @@ export const createEmptyCdkProject = async ( | |
|
||
await cdkCli(['init', 'app', '--language', 'typescript'], projectRoot).run(); | ||
|
||
await execa('npm', ['install', '-D', '@aws-amplify/auth-construct-alpha'], { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't seem like it belongs in "create_empty_cdk_project". Maybe it should be part of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can skip "raw cdk tests" in project manager expansion and just test them with npm. |
||
stdio: 'inherit', | ||
cwd: projectRoot, | ||
}); | ||
|
||
return { projectName, projectRoot }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import { execa } from 'execa'; | ||
import { shortUuid } from '../short_uuid.js'; | ||
import { setupDirAsEsmModule } from './setup_dir_as_esm_module.js'; | ||
|
||
|
@@ -29,5 +30,24 @@ export const createEmptyAmplifyProject = async ( | |
|
||
await setupDirAsEsmModule(projectAmplifyDir); | ||
|
||
await execa( | ||
'npm', | ||
[ | ||
'install', | ||
'-D', | ||
'@aws-amplify/backend', | ||
'@aws-amplify/backend-cli', | ||
'@aws-amplify/auth-construct-alpha', | ||
'@aws-amplify/backend-deployer', | ||
...(projectDirName === 'data-storage-auth' | ||
? ['uuid', '@types/uuid'] | ||
: []), | ||
Comment on lines
+43
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How much, if any, of this belongs in "create_empty_amplify_project"? I can buy that installing backend and backend-cli should belong here, but not so sure about the other stuff. Perhaps individual tests should install those packages if needed. |
||
], | ||
{ | ||
stdio: 'inherit', | ||
cwd: projectRoot, | ||
} | ||
); | ||
|
||
return { projectName, projectRoot, projectAmplifyDir }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,11 @@ export const setupDirAsEsmModule = async (absoluteDirPath: string) => { | |
'es2022', | ||
]; | ||
|
||
await execa('npm', ['install', 'typescript'], { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is another signal to just use create-amplify to boostrap test project. |
||
stdio: 'inherit', | ||
cwd: absoluteDirPath, | ||
}); | ||
|
||
await execa('npx', tscArgs, { | ||
stdio: 'inherit', | ||
cwd: absoluteDirPath, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not use
npm run e2e
at this moment because we'll add more test (e.g.sandbox.test.ts
) later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming the end goal is to replace these with a single call to
PACKAGE_MANAGER_EXECUTABLE=${{matrix.pkg-manager}} npm run e2e
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. We'll eventually use
PACKAGE_MANAGER_EXECUTABLE=${{matrix.pkg-manager}} npm run e2e
when mergepoc/package-manager-support
tomain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave the create amplify as it is and add deployment test for only npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-)
I'd say "leave existing e2e tests as is, create new job with matrix to run create-amplify test (with added deployment step inside test)".