Skip to content

Commit ae1fc1a

Browse files
author
Thomas Reggi
authored
test: reenable deprecation test
NODE-2816
1 parent 0e6375a commit ae1fc1a

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
'use strict';
2+
const exec = require('child_process').exec;
3+
const chai = require('chai');
4+
const expect = chai.expect;
5+
const sinon = require('sinon');
6+
const sinonChai = require('sinon-chai');
7+
require('mocha-sinon');
8+
chai.use(sinonChai);
9+
10+
const utils = require('../tools/utils');
11+
const ClassWithLogger = utils.ClassWithLogger;
12+
const ClassWithoutLogger = utils.ClassWithoutLogger;
13+
const ClassWithUndefinedLogger = utils.ClassWithUndefinedLogger;
14+
const ensureCalledWith = utils.ensureCalledWith;
15+
16+
describe('Deprecation Warnings', function () {
17+
beforeEach(function () {
18+
this.sinon.stub(console, 'error');
19+
});
20+
21+
const defaultMessage = ' is deprecated and will be removed in a later version.';
22+
it.skip('node --no-deprecation flag should suppress all deprecation warnings', {
23+
metadata: { requires: { node: '>=6.0.0' } },
24+
test: function (done) {
25+
exec(
26+
'node --no-deprecation ./test/tools/deprecate_warning_test_program.js',
27+
(err, stdout, stderr) => {
28+
expect(err).to.not.exist;
29+
expect(stdout).to.be.empty;
30+
expect(stderr).to.be.empty;
31+
done();
32+
}
33+
);
34+
}
35+
});
36+
37+
it.skip('node --trace-deprecation flag should print stack trace to stderr', {
38+
metadata: { requires: { node: '>=6.0.0' } },
39+
test: function (done) {
40+
exec(
41+
'node --trace-deprecation ./test/tools/deprecate_warning_test_program.js',
42+
(err, stdout, stderr) => {
43+
expect(err).to.not.exist;
44+
expect(stdout).to.be.empty;
45+
expect(stderr).to.not.be.empty;
46+
47+
// split stderr into separate lines, trimming the first line to just the warning message
48+
const split = stderr.split('\n');
49+
const warning = split.shift().split(')')[1].trim();
50+
51+
// ensure warning message matches expected
52+
expect(warning).to.equal(
53+
'DeprecationWarning: testDeprecationFlags option [maxScan]' + defaultMessage
54+
);
55+
56+
// ensure each following line is from the stack trace, i.e. 'at config.deprecatedOptions.forEach.deprecatedOption'
57+
split.pop();
58+
split.forEach(s => {
59+
expect(s.trim()).to.match(/^at/);
60+
});
61+
62+
done();
63+
}
64+
);
65+
}
66+
});
67+
68+
it.skip('node --throw-deprecation flag should throw error when deprecated function is called', {
69+
metadata: { requires: { node: '>=6.0.0' } },
70+
test: function (done) {
71+
exec(
72+
'node --throw-deprecation ./test/tools/deprecate_warning_test_program.js this_arg_should_never_print',
73+
(err, stdout, stderr) => {
74+
expect(stderr).to.not.be.empty;
75+
expect(err).to.not.exist;
76+
expect(err).to.have.own.property('code').that.equals(1);
77+
78+
// ensure stdout is empty, i.e. that the program threw an error before reaching the console.log statement
79+
expect(stdout).to.be.empty;
80+
done();
81+
}
82+
);
83+
}
84+
});
85+
86+
it('test behavior for classes with an associated logger', function () {
87+
const fakeClass = new ClassWithLogger();
88+
const logger = fakeClass.getLogger();
89+
const stub = sinon.stub(logger, 'warn');
90+
91+
fakeClass.f({ maxScan: 5, snapshot: true });
92+
fakeClass.f({ maxScan: 5, snapshot: true });
93+
expect(stub).to.have.been.calledTwice;
94+
ensureCalledWith(stub, [
95+
'f option [maxScan] is deprecated and will be removed in a later version.',
96+
'f option [snapshot] is deprecated and will be removed in a later version.'
97+
]);
98+
});
99+
100+
it('test behavior for classes without an associated logger', function () {
101+
const fakeClass = new ClassWithoutLogger();
102+
103+
function func() {
104+
fakeClass.f({ maxScan: 5, snapshot: true });
105+
}
106+
107+
expect(func).to.not.throw();
108+
});
109+
110+
it('test behavior for classes with an undefined logger', function () {
111+
const fakeClass = new ClassWithUndefinedLogger();
112+
113+
function func() {
114+
fakeClass.f({ maxScan: 5, snapshot: true });
115+
}
116+
117+
expect(func).to.not.throw();
118+
});
119+
});

0 commit comments

Comments
 (0)