Skip to content
Open
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
36 changes: 36 additions & 0 deletions packages/metro/src/DeltaBundler/__tests__/resolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,42 @@ function dep(name: string): TransformResultDependency {
});
});

describe('blockList config param', () => {
test('hides files matching a pattern in a blockList array', async () => {
setMockFileSystem({
'index.js': '',
'a.js': '',
'blocked.js': '',
});

resolver = await createResolver({
resolver: {blockList: [/blocked\.js$/]},
});

expect(resolver.resolve(p('/root/index.js'), dep('./a'))).toEqual({
type: 'sourceFile',
filePath: p('/root/a.js'),
});
expect(() =>
resolver.resolve(p('/root/index.js'), dep('./blocked')),
).toThrow(/Unable to resolve module \.\/blocked/);
});

test('does not hide any file with an empty blockList array', async () => {
setMockFileSystem({
'index.js': '',
'a.js': '',
});

resolver = await createResolver({resolver: {blockList: []}});

expect(resolver.resolve(p('/root/index.js'), dep('./a'))).toEqual({
type: 'sourceFile',
filePath: p('/root/a.js'),
});
});
});

describe('absolute paths', () => {
test('supports requiring absolute paths', async () => {
setMockFileSystem({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const flattenBlockList = (regexes: ConfigT['resolver']['blockList']) => {
if (!Array.isArray(regexes)) {
return regexes;
}
// An empty list blocks nothing. Joining no patterns would give an empty
// RegExp, which matches every path.
if (regexes.length === 0) {
return /.^/;
}
return new RegExp(
regexes
.map((regex, index) => {
Expand Down
Loading