Skip to content

Commit

Permalink
Add test for packageResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Feb 23, 2024
1 parent 11a6e37 commit 61e150d
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions test/integration/sanity/script-with-packages.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
var expect = require('chai').expect,
sinon = require('sinon');

describe('Scripts with packages', function () {
var _ = require('lodash'),
packageResolverStub = sinon.stub().callsFake(function ({ packages }, callback) {
const resolvedPackages = Object.keys(packages).reduce(function (acc, pkg) {
acc[pkg] = {
data: `module.exports.name = "${pkg}"`
};

return acc;
}, {});

callback(null, resolvedPackages);
});

before(function (done) {
this.run({
collection: {
item: [{
event: [{
listen: 'prerequest',
script: {
exec: [
'const pkg1 = pm.require("pkg1");'
],
packages: {
pkg1: {
id: 'pkg1-id'
}
}
}
}, {
listen: 'test',
script: {
exec: [
'const pkg2 = pm.require("pkg2");'
],
packages: {
pkg1: {
id: 'pkg1-id'
},
pkg2: {
id: 'pkg2-id'
}
}
}
}],
request: {
url: 'https://postman-echo.com/get',
method: 'GET'
}
}]
},
script: {
packageResolver: packageResolverStub
}
}, function (err, results) {
testrun = results;

Check failure on line 60 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

Global variable leak, declare the variable if it is intended to be local

Check failure on line 60 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

'testrun' is not defined
done(err);
});
});

it('should call packageResolver before each event', function () {
expect(packageResolverStub.callCount).to.equal(2);
});

it('should call packageResolver with packages for prerequest script', function () {
var preReqErr = _.get(testrun.prerequest.getCall(0).args[2], '0.error');

Check failure on line 70 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

'testrun' is not defined

expect(preReqErr).to.be.undefined;
expect(packageResolverStub.firstCall.args[0]).to.have.property('packages');
expect(packageResolverStub.firstCall.args[0].packages).to.eql({
pkg1: {
id: 'pkg1-id'
}
});
});

it('should call packageResolver with packages for tests script', function () {
var testErr = _.get(testrun.test.getCall(0).args[2], '0.error');

Check failure on line 82 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

'testrun' is not defined

expect(testErr).to.be.undefined;
expect(packageResolverStub.secondCall.args[0]).to.have.property('packages');
expect(packageResolverStub.secondCall.args[0].packages).to.eql({
pkg1: {
id: 'pkg1-id'
},
pkg2: {
id: 'pkg2-id'
}
});
});

it('should have completed the run', function () {
expect(testrun).to.be.ok;

Check failure on line 97 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

'testrun' is not defined
expect(testrun.done.getCall(0).args[0]).to.be.null;

Check failure on line 98 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

'testrun' is not defined
expect(testrun).to.nested.include({

Check failure on line 99 in test/integration/sanity/script-with-packages.test.js

View workflow job for this annotation

GitHub Actions / Lint

'testrun' is not defined
'done.calledOnce': true,
'start.calledOnce': true
});
});
});

0 comments on commit 61e150d

Please sign in to comment.