-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multi-platform end-to-end tests (#130)
* chore: add multi-platform end-to-end tests * refactor: rename integ to integration
- Loading branch information
1 parent
8d09367
commit 0833d60
Showing
25 changed files
with
1,148 additions
and
5 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,85 @@ | ||
import * as fs from 'fs-extra'; | ||
import * as os from 'os'; | ||
import * as crypto from 'crypto'; | ||
import * as path from 'path'; | ||
import * as execa from 'execa'; | ||
|
||
test('bundling lambda-project to a zip', async () => { | ||
const workDir = getTempDirName(); | ||
const bundleOutput = getTempDirName(); | ||
|
||
// Stage the test project far from the yarn.build project | ||
fs.copySync(path.join(__dirname, 'lambda-project'), workDir, { | ||
recursive: true, | ||
errorOnExist: true, | ||
}); | ||
|
||
// WHEN | ||
yarnCmd(workDir, 'plugin', 'import', BUILD_PLUGIN_PATH); | ||
yarnCmd(workDir, 'install'); | ||
yarnCmd(workDir, 'workspace', 'lambda', 'build'); | ||
yarnCmd(workDir, 'workspace', 'lambda', 'bundle', '--output-directory', bundleOutput); | ||
|
||
// THEN | ||
const zipPath = path.join(bundleOutput, 'bundle.zip'); | ||
|
||
expect(fs.existsSync(zipPath)).toEqual(true); | ||
expect(fs.statSync(zipPath).isFile()).toEqual(true); | ||
}); | ||
|
||
test('run lambda-project after bundling without compression', async () => { | ||
const workDir = getTempDirName(); | ||
const bundleOutput = getTempDirName(); | ||
|
||
// Stage the test project far from the yarn.build project | ||
fs.copySync(path.join(__dirname, 'lambda-project'), workDir, { | ||
recursive: true, | ||
errorOnExist: true, | ||
}); | ||
|
||
// WHEN | ||
yarnCmd(workDir, 'plugin', 'import', BUILD_PLUGIN_PATH); | ||
yarnCmd(workDir, 'install'); | ||
yarnCmd(workDir, 'workspace', 'lambda', 'build'); | ||
yarnCmd(workDir, 'workspace', 'lambda', 'bundle', '--output-directory', bundleOutput, '--no-compress'); | ||
|
||
// THEN | ||
expect(fs.existsSync(path.join(bundleOutput, 'package.json'))).toEqual(true); | ||
expect(fs.existsSync(path.join(bundleOutput, '.pnp.cjs'))).toEqual(true); | ||
expect(fs.existsSync(path.join(bundleOutput, '.yarn'))).toEqual(true); | ||
expect(fs.readdirSync(path.join(bundleOutput, '.yarn', 'cache'))).toEqual([ | ||
".gitignore", | ||
expect.stringMatching(/^uglify-js.*\.zip$/), | ||
// Notably, the cache excludes the dev deps. | ||
]); | ||
|
||
// Now run the bundled code to see that it works! | ||
// lambda-project's dependencies look like this: lambda -> lib -> uglify-js | ||
// Calling the lambda's api handler tests the uglify-js transitive dependency | ||
const execResult = execa.sync('node', ['--require', './.pnp.cjs', 'packages/lambda/dist/api.js'], { | ||
cwd: bundleOutput, | ||
}); | ||
|
||
const responsePayload = JSON.parse(execResult.stdout); | ||
|
||
expect(responsePayload).toEqual({ | ||
statusCode: 200, | ||
// The following shows that the lambda package called lib, and lib used | ||
// uglify-js. | ||
body: "\"function foobar(){} // MUGLIFIED\"", | ||
}); | ||
}); | ||
|
||
function yarnCmd(workDir: string, ...args: string[]) { | ||
execa.sync('yarn', args, { | ||
cwd: workDir, | ||
stdout: process.stdout, | ||
stderr: process.stderr, | ||
}); | ||
} | ||
|
||
function getTempDirName() { | ||
return path.join(os.tmpdir(), 'integ' + crypto.randomBytes(10).toString('hex')); | ||
} | ||
|
||
const BUILD_PLUGIN_PATH = path.join(__dirname, '..', 'packages', 'plugins', 'plugin-build', 'bundles', '@yarnpkg', 'plugin-build.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,9 @@ | ||
dist | ||
|
||
.pnp.cjs | ||
.yarn/* | ||
!.yarn/patches | ||
#!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
Large diffs are not rendered by default.
Oops, something went wrong.
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,2 @@ | ||
nodeLinker: pnp | ||
yarnPath: .yarn/releases/yarn-berry.cjs |
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 @@ | ||
{ | ||
"name": "lambda-project", | ||
"workspaces": [ | ||
"packages/*" | ||
] | ||
} |
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,16 @@ | ||
{ | ||
"name": "lambda", | ||
"version": "1.0.0", | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"build": "tsc --project tsconfig.dev.json" | ||
}, | ||
"dependencies": { | ||
"lib": "1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.84", | ||
"@types/node": "14.17.6", | ||
"typescript": "^4.4.4" | ||
} | ||
} |
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,32 @@ | ||
/* eslint-disable */ | ||
// @ts-ignore | ||
import type * as lambda from 'aws-lambda'; | ||
// @ts-ignore | ||
import {muglify} from 'lib'; | ||
|
||
export async function handler(): Promise<lambda.APIGatewayProxyResult> { | ||
try { | ||
const value = muglify('function foobar() { /* WILL BE STRIPPED OUT */ }'); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(value), | ||
}; | ||
} catch (e) { | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify(e), | ||
}; | ||
} | ||
} | ||
|
||
// When run, this file executes the handler and outputs the result. | ||
if (require.main === module) { | ||
handler() | ||
.then(res => { | ||
console.log(JSON.stringify(res)); | ||
}) | ||
.catch(e => { | ||
console.error(e); | ||
}); | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"experimentalDecorators": true, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"lib": [ | ||
"es2019" | ||
], | ||
"module": "CommonJS", | ||
"noEmitOnError": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"resolveJsonModule": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictPropertyInitialization": true, | ||
"stripInternal": true, | ||
"target": "ES2019", | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"name": "lib", | ||
"version": "1.0.0", | ||
"packageManager": "[email protected]", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc --project tsconfig.dev.json" | ||
}, | ||
"devDependencies": { | ||
"@types/uglify-js": "^3.13.1", | ||
"typescript": "^4.4.4" | ||
}, | ||
"dependencies": { | ||
"uglify-js": "^3.14.2" | ||
} | ||
} |
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 @@ | ||
/* eslint-disable */ | ||
// @ts-ignore | ||
import uglify from 'uglify-js'; | ||
|
||
export function muglify(code: string): string { | ||
const minifyOutput = uglify.minify(code); | ||
|
||
if (minifyOutput.error) { | ||
throw minifyOutput.error; | ||
} | ||
|
||
return minifyOutput.code + ' // MUGLIFIED'; | ||
} |
Oops, something went wrong.