Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lint
  • Loading branch information
dyladan committed Dec 1, 2023
commit 6bfc74b101e1f5759a07ee5f8952a09bfb516804
24 changes: 12 additions & 12 deletions api/test/tree-shaking/tree-shaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as realFs from 'fs';
/**
* Verify that tree-shaking can be properly applied on the @opentelemetry/api package.
* Unused optional apis should be able to be removed from the final bundle.
*
*
* Webpack doesn't run in node 8 because it requires BigInt. Since we are testing
* build tooling here, we can safely skip tooling we know can't run anyway.
*/
Expand All @@ -46,19 +46,19 @@ if (parseInt(process.version.split('.')[0], 10) >= 10) {
},
];
const APIMatcher = /(?:class|function) (\w+API)/g;

const sourceCodePath = path.join(__dirname, 'test.js');
const outputPath = path.join(__dirname, 'output');
const outputFilename = path.join(outputPath, 'bundle.js');

afterEach(() => {
try {
mfs.unlinkSync(outputFilename);
} catch {
/** ignore */
}
});

for (const testAPI of testAPIs) {
it(`verify ${testAPI.name}`, async () => {
const sourceCode = `
Expand All @@ -67,7 +67,7 @@ if (parseInt(process.version.split('.')[0], 10) >= 10) {
`;
mfs.mkdirpSync(path.dirname(sourceCodePath));
mfs.writeFileSync(sourceCodePath, sourceCode, { encoding: 'utf8' });

const compiler = webpack({
entry: sourceCodePath,
output: {
Expand All @@ -82,18 +82,18 @@ if (parseInt(process.version.split('.')[0], 10) >= 10) {
concatenateModules: false,
},
});

const fs = new Union();
fs.use(mfs as any).use(realFs);

//direct webpack to use unionfs for file input
compiler.inputFileSystem = fs;
//direct webpack to output to memoryfs rather than to disk
compiler.outputFileSystem = {
...mfs,
join: path.join,
} as any;

const stats = await new Promise<webpack.Stats>((resolve, reject) => {
compiler.run((err, stats) => {
if (err) {
Expand All @@ -104,7 +104,7 @@ if (parseInt(process.version.split('.')[0], 10) >= 10) {
});
assert.deepStrictEqual(stats.compilation.errors, []);
assert.deepStrictEqual(stats.compilation.warnings, []);

const outputFile = mfs.readFileSync(outputFilename, 'utf8') as string;
const matches = new Set();
let match;
Expand All @@ -114,12 +114,12 @@ if (parseInt(process.version.split('.')[0], 10) >= 10) {
matches.add(match[1]);
}
} while (match);

// Remove allowed apis from checking list.
allowedAPIs.forEach(it => matches.delete(it));

assert.deepStrictEqual(Array.from(matches), [testAPI.name]);
});
}
})
});
}