Skip to content
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
1 change: 1 addition & 0 deletions tools/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BacktracePlugin } from './BacktracePlugin';
export { BacktracePlugin };
export default BacktracePlugin;
export { BacktracePluginOptions } from '@backtrace/sourcemap-tools';
35 changes: 0 additions & 35 deletions tools/webpack-plugin/tests/__mocks__/TestDebugIdGenerator.ts

This file was deleted.

37 changes: 13 additions & 24 deletions tools/webpack-plugin/tests/e2e/createE2ETest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Ok, SourceProcessor, SymbolUploader, ZipArchive } from '@backtrace/sourcemap-tools';
import assert from 'assert';
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';
import webpack from 'webpack';
import { asyncWebpack, expectSuccess, getFiles, removeDir, webpackModeTest } from './helpers';

Expand All @@ -19,9 +19,7 @@ export function createE2ETest(configBuilder: (mode: webpack.Configuration['mode'
}

function mockProcessor() {
return jest
.spyOn(SourceProcessor.prototype, 'processSourceAndSourceMapFiles')
.mockImplementation(async (_, __, debugId) => Ok({ debugId: debugId ?? 'debugId' } as never));
return jest.spyOn(SourceProcessor.prototype, 'processSourceAndSourceMapFiles');
}

function mockZipArchiveAppend() {
Expand All @@ -34,7 +32,7 @@ export function createE2ETest(configBuilder: (mode: webpack.Configuration['mode'
let zipArchiveAppendSpy: ReturnType<typeof mockZipArchiveAppend>;

beforeAll(async () => {
jest.resetAllMocks();
jest.restoreAllMocks();

uploadSpy = mockUploader();
processSpy = mockProcessor();
Expand All @@ -50,44 +48,35 @@ export function createE2ETest(configBuilder: (mode: webpack.Configuration['mode'
result = webpackResult;
}, 120000);

it('should call SourceProcessor for every emitted source file and sourcemap pair', async () => {
it('should call SourceProcessor for every emitted source file', async () => {
const outputDir = result.compilation.outputOptions.path;
assert(outputDir);

const jsFiles = await getFiles(outputDir, /.js$/);
expect(jsFiles.length).toBeGreaterThan(0);

const processedPairs = processSpy.mock.calls.map(
([p1, p2]) => [path.resolve(p1), p2 ? path.resolve(p2) : undefined] as const,
);
for (const file of jsFiles) {
const content = await fs.promises.readFile(file, 'utf8');
const matches = [...content.matchAll(/^\/\/# sourceMappingURL=(.+)$/gm)];
expect(matches.length).toEqual(1);
const [, sourceMapPath] = matches[0];

expect(processedPairs).toContainEqual([
path.resolve(file),
path.resolve(path.dirname(file), sourceMapPath),
]);
}
const processedFiles = processSpy.mock.calls
.map(([sourcePath]) => path.resolve(sourcePath))
.sort((a, b) => a.localeCompare(b));

expect(processedFiles).toEqual(jsFiles.sort((a, b) => a.localeCompare(b)));
});

it('should append every emitted sourcemap to archive', async () => {
const outputDir = result.compilation.outputOptions.path;
assert(outputDir);

const mapFiles = await getFiles(outputDir, /.js.map$/);
const mapFiles = (await getFiles(outputDir, /.js.map$/)).map((f) => path.basename(f));
expect(mapFiles.length).toBeGreaterThan(0);

const uploadedFiles = zipArchiveAppendSpy.mock.calls.map((c) => path.resolve(c[1] as string));
const uploadedFiles = zipArchiveAppendSpy.mock.calls.map(([name]) => name);
for (const file of mapFiles) {
expect(uploadedFiles).toContain(path.resolve(file));
expect(uploadedFiles).toContainEqual(expect.stringContaining(file));
}
});

it('should upload archive', async () => {
expect(uploadSpy).toBeCalledWith(expect.any(ZipArchive));
expect(uploadSpy).toHaveBeenCalledWith(expect.any(Readable));
});
});
}
13 changes: 0 additions & 13 deletions tools/webpack-plugin/tests/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs';
import path from 'path';
import webpack from 'webpack';
import { BacktracePlugin, BacktracePluginOptions } from '../../src';
import { TestDebugIdGenerator } from '../__mocks__/TestDebugIdGenerator';

export interface BaseConfigOptions {
tsconfigPath?: string;
Expand Down Expand Up @@ -62,18 +61,6 @@ export function expectSuccess(stats?: webpack.Stats): asserts stats is webpack.S
}
}

export async function expectSourceSnippet(content: string) {
TestDebugIdGenerator.testForSourceSnippet(content);
}

export async function expectSourceComment(content: string) {
TestDebugIdGenerator.testForSourceComment(content);
}

export async function expectSourceMapSnippet(content: string) {
TestDebugIdGenerator.testForSourceMapKey(content);
}

export async function getFiles(dir: string, test?: RegExp) {
const files = (await fs.promises.readdir(dir)).map((f) => path.join(dir, f));
if (test) {
Expand Down
3 changes: 2 additions & 1 deletion tools/webpack-plugin/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
"outDir": "./lib",
"lib": []
},
"exclude": ["node_modules", "tests", "lib"]
}
3 changes: 3 additions & 0 deletions tools/webpack-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2020"]
},
"references": [
{
"path": "../sourcemap-tools/tsconfig.json"
Expand Down
Loading