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

test: test source map support for stack traces #1016

Merged
merged 1 commit into from
May 3, 2019
Merged
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
21 changes: 21 additions & 0 deletions test/fixtures/source-maps-test/external-source-map.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/source-maps-test/external-source-map.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/fixtures/source-maps-test/external-source-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2019 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Used in test-span-data as part of a check for source map support in stack
// traces.
export const applyGeneric = <T>(fn: () => T): T => fn();
21 changes: 21 additions & 0 deletions test/fixtures/source-maps-test/inline-source-map.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/fixtures/source-maps-test/inline-source-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2019 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Used in test-span-data as part of a check for source map support in stack
// traces.
export const applyGeneric = <T>(fn: () => T): T => fn();
21 changes: 21 additions & 0 deletions test/fixtures/source-maps-test/inline-sources.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions test/fixtures/source-maps-test/no-source-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
/**
* Copyright 2019 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
exports.__esModule = true;
// Used in test-span-data as part of a check for source map support in stack
// traces.
exports.applyGeneric = function (fn) { return fn(); };
43 changes: 43 additions & 0 deletions test/test-span-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,49 @@ describe('SpanData', () => {
myFunction();
});

// Dependent on ./fixtures/source-maps-test
describe('stack traces with/without source maps', () => {
const sourceMapTypes =
['external-source-map', 'inline-source-map', 'inline-sources'];
const getSourceMapTestStackFrame = (spanData: CommonSpanData) => {
const stack = spanData.span.labels[TraceLabels.STACK_TRACE_DETAILS_KEY];
assert.ok(stack);
const frames = JSON.parse(stack);
assert.ok(frames && frames.stack_frame);
assert.ok(Array.isArray(frames.stack_frame));
const stackFrame = frames.stack_frame[1];
return stackFrame;
};

for (const sourceMapType of sourceMapTypes) {
it(`uses source maps when available in stack traces: ${sourceMapType}`,
() => {
const {applyGeneric} =
require(`./fixtures/source-maps-test/${sourceMapType}`) as
{applyGeneric: <T>(fn: () => T) => T};
const spanData =
applyGeneric(() => new CommonSpanData(trace, 'name', '0', 0));
const stackFrame = getSourceMapTestStackFrame(spanData);
// Source maps should give us this exact information.
assert.ok(stackFrame.file_name.endsWith(`${sourceMapType}.ts`));
assert.strictEqual(stackFrame.line_number, 19);
assert.strictEqual(stackFrame.column_number, 52);
});
}

it(`doesn't break when there are no source maps`, () => {
const {applyGeneric} =
require(`./fixtures/source-maps-test/no-source-map`) as
{applyGeneric: <T>(fn: () => T) => T};
const spanData =
applyGeneric(() => new CommonSpanData(trace, 'name', '0', 0));
const stackFrame = getSourceMapTestStackFrame(spanData);
assert.ok(stackFrame.file_name.endsWith('no-source-map.js'));
assert.strictEqual(stackFrame.line_number, 20);
assert.strictEqual(stackFrame.column_number, 47);
});
});

it(`doesn't call TraceWriter#writeTrace when ended`, () => {
const spanData = new CommonSpanData(trace, 'name', '0', 0);
spanData.endSpan();
Expand Down