Skip to content
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
30 changes: 25 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# This workflow will do a clean install of node dependencies, lint the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI
Expand All @@ -9,11 +9,28 @@ on:
pull_request:
branches: [master]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
- run: npm install
- run: npm run lint

build:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.node == 'latest' }}

strategy:
fail-fast: false
matrix:
include:
- node: 18
Expand All @@ -28,10 +45,13 @@ jobs:
npm: latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ matrix.node }}
- name: Update npm
run: npm install -g npm@${{ matrix.npm }}
- run: node --version && npm --version
- run: npm install
- run: npm test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"test": "nyc --reporter=html --reporter=text mocha './test/{,!(fixtures)/**/}*test.js'"
},
"dependencies": {
"adm-zip": "^0.5.2",
"axios": "1.15.0",
"adm-zip": "^0.6.1",
"axios": "1.20.0",
"chalk": "^4.1.0",
"form-data": "^3.0.0",
"glob": "^7.1.6",
Expand Down
3 changes: 2 additions & 1 deletion src/sourcemaps/signed-url-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const AdmZip = require('adm-zip');
const axios = require('axios');
const zipFile = new AdmZip();

class SignedUrlUploader {
constructor(requester) {
Expand All @@ -20,6 +19,8 @@ class SignedUrlUploader {
}

zipFiles() {
// A fresh archive per call, so entries don't carry over between uploads.
const zipFile = new AdmZip();

try {
zipFile.addFile('manifest.json', this.requester.manifestData);
Expand Down
10 changes: 3 additions & 7 deletions test/sourcemaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ describe('rollbar-cli upload-sourcemaps', function() {

expect(lines.length).to.equal(14);

for(let i; i < lines.length; i+=2) {
expect(lines[i]).to.have.string('[Found ]');
}
expect(lines.filter((line) => line.startsWith('[Found ]'))).to.have.lengthOf(5);
});

it('uploads react project via signed URL', function() {
this.timeout(5000);

const stdout = execSync('./bin/rollbar upload-sourcemaps ./test/fixtures/builds/react16/build --access-token 1234 --url-prefix "http://localhost:3000/" --code-version react16 -D --signed-url');
const stdout = execSync('./bin/rollbar upload-sourcemaps ./test/fixtures/builds/react16/build --access-token 1234 --url-prefix "http://localhost:3000/" --code-version react16 -D --next');

const lines = stdout.toString().split('\n');

expect(lines.length).to.equal(14);

for(let i; i < lines.length; i+=2) {
expect(lines[i]).to.have.string('[Found ]');
}
expect(lines.filter((line) => line.startsWith('[Found ]'))).to.have.lengthOf(5);
});
});
73 changes: 73 additions & 0 deletions test/sourcemaps/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const Command = require('../../src/sourcemaps/command');
const Output = require('../../src/common/output');
const yargs = require('yargs');
const sinon = require('sinon');
const axios = require('axios');
const AdmZip = require('adm-zip');
const RollbarAPI = require('../../src/common/rollbar-api');

describe('Command()', function() {
beforeEach(function() {
Expand Down Expand Up @@ -56,3 +59,73 @@ describe('Command()', function() {
expect(stubSuccess.callCount).to.equal(3);
});
});

describe('.handler() with --next', function() {
const signedUrl = 'https://storage.example.com/bundle.zip?signature=abc';
const argv = {
path: './test/fixtures/builds/angular9/dist/app',
'access-token': '1234',
'url-prefix': 'http://localhost:3000/',
'code-version': 'angular9',
next: true,
quiet: true
};

afterEach(function() {
sinon.restore();
});

it('requests a signed URL and uploads a zip of the manifest and maps', async function() {
const request = sinon.stub(RollbarAPI.prototype, 'sigendURLsourcemaps').resolves({
err: 0,
result: { project_id: 42, signed_url: signedUrl }
});
const put = sinon.stub(axios, 'put').resolves({ status: 200 });

await Command.handler(argv);

expect(request.firstCall.args[0]).to.deep.equal({
version: 'angular9',
baseUrl: 'http://localhost:3000/'
});
expect(put.callCount).to.equal(1);
expect(put.firstCall.args[0]).to.equal(signedUrl);

const zip = new AdmZip(put.firstCall.args[1]);
expect(zip.getEntries().map((entry) => entry.entryName)).to.have.members([
'manifest.json',
'main-es5.js.map',
'polyfills-es5.js.map',
'runtime-es5.js.map',
'styles-es5.js.map',
'vendor-es5.js.map'
]);
expect(JSON.parse(zip.readAsText('manifest.json'))).to.deep.equal({
projectID: 42,
version: 'angular9',
baseUrl: 'http://localhost:3000/'
});
});

it('does not upload when the signed URL request fails', async function() {
sinon.stub(RollbarAPI.prototype, 'sigendURLsourcemaps').resolves({
err: 1,
message: 'invalid access token'
});
const put = sinon.stub(axios, 'put');

await Command.handler(argv);

expect(put.called).to.be.false;
});

it('does not request or upload on a dry run', async function() {
const request = sinon.stub(RollbarAPI.prototype, 'sigendURLsourcemaps');
const put = sinon.stub(axios, 'put');

await Command.handler(Object.assign({}, argv, { 'dry-run': true }));

expect(request.called).to.be.false;
expect(put.called).to.be.false;
});
});
Loading
Loading