Skip to content
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

Refactor/typescript #205

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ event.json
headless-chromium-amazonlinux-2017-03.zip
.eslintcache
packages/lambda/integration-test/headless-chromium
.rpt2_cache
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"homepage": "https://github.com/adieuadieu/serverless-chrome",
"dependencies": {},
"devDependencies": {
"@types/node": "^8.10.48",
"ava": "0.25.0",
"babel-core": "6.26.3",
"babel-eslint": "8.2.3",
Expand All @@ -66,11 +67,19 @@
"prettier": "1.12.1",
"prettier-eslint": "8.8.1",
"prettier-eslint-cli": "4.7.1",
"tap-xunit": "2.3.0"
"tap-xunit": "2.3.0",
"ts-node": "^8.1.0"
},
"ava": {
"require": "babel-register",
"babel": "inherit"
"require": [
"ts-node/register",
"babel-register"
],
"babel": "inherit",
"extensions": [
"ts",
"js"
]
},
"babel": {
"sourceMaps": "inline",
Expand Down
31 changes: 10 additions & 21 deletions packages/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://github.com/adieuadieu/serverless-chrome/tree/master/packages/lambda",
"license": "MIT",
"engines": {
"node": ">= 6.10"
"node": ">= 8.10"
},
"config": {
"jsSrc": "src/"
Expand All @@ -34,6 +34,7 @@
"clean": "rm -Rf dist/ ./**.zip",
"test": "npm run test:integration",
"test:integration": "scripts/test-integration.sh",
"lint": "tslint src/**/*.ts",
"build": "rollup -c",
"dev": "rollup -c -w",
"prepublishOnly": "npm run clean && npm run build",
Expand All @@ -43,30 +44,18 @@
"upgrade-dependencies": "yarn upgrade-interactive --latest --exact"
},
"dependencies": {
"debug": "^4.1.1",
"extract-zip": "1.6.6"
},
"devDependencies": {
"@types/debug": "^4.1.4",
"@types/node": "^8.10.48",
"ava": "0.25.0",
"babel-core": "6.26.3",
"babel-preset-env": "1.7.0",
"babel-register": "6.26.0",
"chrome-launcher": "0.10.2",
"rollup": "0.59.1",
"rollup-plugin-babel": "3.0.4",
"rollup-plugin-node-resolve": "3.3.0"
},
"babel": {
"sourceMaps": true,
"presets": [
[
"env",
{
"modules": "commonjs",
"targets": {
"node": "6.10"
}
}
]
]
"rollup": "^1.11.3",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-typescript2": "^0.21.0",
"tslint": "^5.16.0",
"typescript": "^3.4.5"
}
}
21 changes: 4 additions & 17 deletions packages/lambda/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import typescript from 'rollup-plugin-typescript2'

export default {
input: 'src/index.js',
input: 'src/index.ts',
output: [
{ file: 'dist/bundle.cjs.js', format: 'cjs' },
{ file: 'dist/bundle.es.js', format: 'es' },
Expand All @@ -20,20 +20,7 @@ export default {
// ES2015 modules
// modulesOnly: true, // Default: false
}),
babel({
babelrc: false,
presets: [
[
'env',
{
modules: false,
targets: {
node: '6.10',
},
},
],
],
}),
typescript(),
],
external: ['fs', 'child_process', 'net', 'http', 'path', 'chrome-launcher'],
external: ['fs', 'child_process', 'net', 'path', 'chrome-launcher', 'debug'],
}
17 changes: 0 additions & 17 deletions packages/lambda/src/flags.js

This file was deleted.

117 changes: 0 additions & 117 deletions packages/lambda/src/index.js

This file was deleted.

40 changes: 0 additions & 40 deletions packages/lambda/src/index.test.js

This file was deleted.

40 changes: 40 additions & 0 deletions packages/lambda/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import test from "ava";
import * as chromeFinder from "chrome-launcher/dist/chrome-finder";
import launch from "./index";

const DEFAULT_TEST_FLAGS = ["--headless"];

async function getLocalChromePath() {
const installations = await chromeFinder[process.platform]();

if (installations.length === 0) {
throw new Error("No Chrome Installations Found");
}

return installations[0];
}

test.serial("Chrome should launch using LocalChromeLauncher", async (t) => {
const chromePath = await getLocalChromePath();
const chrome = await launch({
flags: DEFAULT_TEST_FLAGS,
chromePath,
port: 9220,
});

t.notThrows(chrome);

const instance = await chrome;

t.truthy(instance.pid, "pid should be set");
t.truthy(instance.port, "port should be set");
t.is(instance.port, 9220, "port should be 9220");

await instance.kill();
});

// Covered by the integration-test.
test("Chrome should launch using LambdaChromeLauncher", (t) => {
// @TODO: proper test..
t.pass();
});
Loading