Skip to content

Commit b37a340

Browse files
authored
Merge pull request #8 from grafana/elliot/tests
adding tests
2 parents f135d06 + 57337ce commit b37a340

26 files changed

+2889
-35
lines changed

.github/workflows/publish-npm.yml

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
with:
2626
cmd: install --frozen-lockfile
2727

28+
- name: Run tests
29+
uses: borales/actions-yarn@v4
30+
with:
31+
cmd: test
32+
2833
- name: Build production bundle
2934
uses: borales/actions-yarn@v4
3035
with:

.github/workflows/run-tests.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: run-tests
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
run-tests:
7+
name: Run tests
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.event.pull_request.head.ref }}
14+
fetch-depth: 0
15+
16+
- name: Install dependencies
17+
uses: borales/actions-yarn@v5
18+
with:
19+
cmd: install --frozen-lockfile
20+
21+
- name: Setup NPM
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 18.x
25+
registry-url: "https://registry.npmjs.org"
26+
27+
- name: Run test manually
28+
run: |
29+
cd packages/faro-rollup/src/test
30+
yarn install
31+
cd ../..
32+
yarn install
33+
cd ../faro-webpack/src/test
34+
yarn install
35+
yarn build
36+
cd ../../..
37+
yarn test
38+
39+
- name: Build production bundle
40+
uses: borales/actions-yarn@v5
41+
with:
42+
cmd: build

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ src/index.js
55
src/index.d.ts
66
yalc.lock
77
.yalc
8-
.npmrc
8+
.npmrc
9+
lerna-debug.log

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
],
77
"scripts": {
88
"build": "lerna run build",
9-
"publish": "lerna publish"
9+
"publish": "lerna publish",
10+
"test": "lerna run test"
1011
},
1112
"author": "Grafana Labs",
1213
"license": "Apache-2.0",

packages/faro-bundlers-shared/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"license": "Apache-2.0",
1313
"scripts": {
14-
"build": "rollup --config rollup.config.mjs"
14+
"build": "rollup --config rollup.config.mjs",
15+
"test": "echo \"No tests yet...\" && exit 0"
1516
},
1617
"devDependencies": {
1718
"@rollup/plugin-typescript": "^11.1.5",

packages/faro-rollup/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@grafana/faro-rollup-plugin",
33
"version": "0.0.12",
44
"description": "Upload a source map to the Faro source map API from a Rollup build pipeline",
5+
"type": "module",
56
"main": "dist/cjs/index.js",
67
"module": "dist/esm/index.mjs",
78
"repository": {
@@ -12,12 +13,17 @@
1213
"license": "Apache-2.0",
1314
"author": "Grafana Labs",
1415
"scripts": {
15-
"build": "rollup --config rollup.config.mjs"
16+
"build": "rollup --config rollup.config.mjs",
17+
"test": "ava src/index.test.js"
18+
},
19+
"devDependencies": {
20+
"ava": "^3.8.1"
1621
},
1722
"dependencies": {
1823
"@grafana/faro-bundlers-shared": "^0.0.12",
1924
"cross-fetch": "^4.0.0",
20-
"magic-string": "^0.30.5"
25+
"magic-string": "^0.30.5",
26+
"rollup": "^4.1.1"
2127
},
2228
"publishConfig": {
2329
"access": "public"

packages/faro-rollup/rollup.config.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ export default {
2929
plugins: [
3030
typescript({
3131
outDir: "dist",
32+
exclude: ["**/*.test.ts"],
3233
}),
3334
babel({
3435
extensions,
3536
babelHelpers: "bundled",
3637
include: ["src/**/*"],
37-
exclude: /node_modules/
38+
exclude: [/node_modules/, /test/, "*.test.ts"]
3839
}),
3940
json(),
4041
resolve({
@@ -43,7 +44,8 @@ export default {
4344
preferBuiltins: true,
4445
}),
4546
commonjs({
46-
include: /node_modules/
47+
include: /node_modules/,
48+
exclude: "*.test.ts"
4749
}),
4850
],
4951
};
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import test from 'ava';
2+
import { rollup } from 'rollup';
3+
import config from './test/rollup.config.cjs';
4+
5+
test('rollup', async t => {
6+
const bundle = await rollup(config);
7+
const output = await bundle.write(config.output);
8+
9+
t.truthy(output.output[0].code.startsWith(`(function(){try{var g=typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};g["__faroBundleId_rollup-test-app"]="test"`));
10+
});

packages/faro-rollup/src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export default function faroUploader(
1919
const {
2020
endpoint,
2121
appId,
22+
apiKey,
2223
orgId,
24+
stackId,
2325
appName,
2426
outputFiles,
2527
keepSourcemaps,
@@ -89,6 +91,8 @@ export default function faroUploader(
8991
filesToUpload.pop();
9092
const result = await uploadCompressedSourceMaps({
9193
sourcemapEndpoint,
94+
apiKey,
95+
stackId,
9296
orgId: orgId,
9397
files: filesToUpload,
9498
keepSourcemaps: !!keepSourcemaps,
@@ -109,6 +113,8 @@ export default function faroUploader(
109113
if (!gzipContents) {
110114
const result = await uploadSourceMap({
111115
sourcemapEndpoint,
116+
apiKey,
117+
stackId,
112118
filename,
113119
orgId: orgId,
114120
filePath: `${outputPath}/${filename}`,
@@ -126,6 +132,8 @@ export default function faroUploader(
126132
if (filesToUpload.length) {
127133
const result = await uploadCompressedSourceMaps({
128134
sourcemapEndpoint,
135+
apiKey,
136+
stackId,
129137
orgId: orgId,
130138
files: filesToUpload,
131139
keepSourcemaps: !!keepSourcemaps,

packages/faro-rollup/src/test/bundle.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<script type="text/javascript" src="bundle.js"></script>
4+
</body>
5+
</html>

packages/faro-rollup/src/test/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.write('<h1>Hello World</h1>');
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "webpack-test-app",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"build": "rollup --config rollup.config.cjs"
7+
},
8+
"dependencies": {
9+
"@grafana/faro-rollup-plugin": "^0.0.12"
10+
},
11+
"license": "MIT",
12+
"devDependencies": {
13+
"webpack-cli": "^5.1.4"
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const faroUploader = require('@grafana/faro-rollup-plugin');
2+
3+
module.exports =
4+
{
5+
input: "./src/test/main.js",
6+
output: {
7+
file: './dist/bundle.js'
8+
},
9+
plugins: [
10+
faroUploader({
11+
appName: 'rollup-test-app',
12+
endpoint: 'http://localhost:8000/faro/api/v1',
13+
appId: '1',
14+
orgId: '1',
15+
gzipContents: true,
16+
bundleId: 'test'
17+
})
18+
]
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"esModuleInterop": true
6+
}
7+
}

0 commit comments

Comments
 (0)