-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathaws-npm.test.ts
82 lines (74 loc) · 2.1 KB
/
aws-npm.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import test, { ExecutionContext } from "ava";
import { Lambda } from "@aws-sdk/client-lambda";
import { v4 as uuid } from "uuid";
import { AwsLayerInfo, npmInstall } from "../src/aws/aws-npm";
import { title } from "./fixtures/util";
const lambda = new Lambda({ region: "us-west-2" });
async function testNpmInstall(
t: ExecutionContext,
packageJsonContents: string,
bigPackage: boolean
) {
const LayerName = `faast-test-layer-${uuid()}`;
const FunctionName = `faast-${uuid()}`;
let layerInfo: AwsLayerInfo | undefined;
let installLog: string;
try {
const result = await npmInstall({
LayerName,
FunctionName,
packageJsonContents,
region: "us-west-2",
quiet: true,
retentionInDays: 1
});
if (bigPackage) {
t.true(result.zipSize! > 50 * 2 ** 20);
}
({ layerInfo, installLog } = result);
t.is(layerInfo.LayerName, LayerName);
t.true(typeof layerInfo.Version === "number");
t.regex(installLog, /added [0-9]+ package/);
const cachedResult = await npmInstall({
LayerName,
FunctionName,
packageJsonContents,
region: "us-west-2",
quiet: true,
retentionInDays: 1
});
t.deepEqual(cachedResult.layerInfo, layerInfo);
} finally {
if (layerInfo) {
await lambda.deleteLayerVersion({
LayerName,
VersionNumber: layerInfo.Version
});
}
}
}
const puppeteerPackage = JSON.stringify({
dependencies: {
"chrome-aws-lambda": "latest",
"puppeteer-core": "latest",
typescript: "latest",
"aws-sdk": "latest"
}
});
test.serial(
title("aws", `npm-install with Lambda Layer larger than 50MB`),
testNpmInstall,
puppeteerPackage,
true
);
const tslibPackage = JSON.stringify({
dependencies: {
tslib: "latest"
}
});
test.serial(
title("aws", "npm-install with Lambda Layer less than 50MB"),
testNpmInstall,
tslibPackage,
false
);