mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[now-build-utils] Ensure function paths are relative to the project and improve the error message (#3312)
* [now-build-utils] Ensure function paths are relative to the project and improve the error message * Update packages/now-build-utils/src/detect-builders.ts Co-Authored-By: Steven <steven@ceriously.com> * Update packages/now-build-utils/src/detect-builders.ts Co-Authored-By: Steven <steven@ceriously.com>
This commit is contained in:
77
packages/now-build-utils/test/unit.test.js
vendored
77
packages/now-build-utils/test/unit.test.js
vendored
@@ -637,11 +637,13 @@ describe('Test `detectBuilders`', () => {
|
||||
|
||||
it('Must include includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { includeFiles: 'text/include.txt' }
|
||||
}
|
||||
'api/test.js': { includeFiles: 'text/include.txt' },
|
||||
};
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, { functions });
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
functions,
|
||||
});
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
@@ -649,35 +651,19 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders[0].config).toMatchObject({
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
includeFiles: 'text/include.txt'
|
||||
includeFiles: 'text/include.txt',
|
||||
});
|
||||
});
|
||||
|
||||
it('Must include excludeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { excludeFiles: 'text/exclude.txt' }
|
||||
}
|
||||
'api/test.js': { excludeFiles: 'text/exclude.txt' },
|
||||
};
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
expect(builders[0].use).toBe('@now/node');
|
||||
expect(builders[0].config).toMatchObject({
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
excludeFiles: 'text/exclude.txt'
|
||||
});
|
||||
});
|
||||
|
||||
it('Must include excludeFiles and includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { excludeFiles: 'text/exclude.txt', includeFiles: 'text/include.txt' }
|
||||
}
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
@@ -686,14 +672,37 @@ describe('Test `detectBuilders`', () => {
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
excludeFiles: 'text/exclude.txt',
|
||||
includeFiles: 'text/include.txt'
|
||||
});
|
||||
});
|
||||
|
||||
it('Must include excludeFiles and includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': {
|
||||
excludeFiles: 'text/exclude.txt',
|
||||
includeFiles: 'text/include.txt',
|
||||
},
|
||||
};
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
functions,
|
||||
});
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
expect(builders[0].use).toBe('@now/node');
|
||||
expect(builders[0].config).toMatchObject({
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
excludeFiles: 'text/exclude.txt',
|
||||
includeFiles: 'text/include.txt',
|
||||
});
|
||||
});
|
||||
|
||||
it('Must fail for includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { includeFiles: { test: 1 } }
|
||||
}
|
||||
'api/test.js': { includeFiles: { test: 1 } },
|
||||
};
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { errors } = await detectBuilders(files, null, { functions });
|
||||
@@ -704,8 +713,8 @@ describe('Test `detectBuilders`', () => {
|
||||
|
||||
it('Must fail for excludeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { excludeFiles: { test: 1 } }
|
||||
}
|
||||
'api/test.js': { excludeFiles: { test: 1 } },
|
||||
};
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { errors } = await detectBuilders(files, null, { functions });
|
||||
@@ -713,6 +722,18 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(errors).not.toBe(null);
|
||||
expect(errors[0].code).toBe('invalid_function_property');
|
||||
});
|
||||
|
||||
it('Must fail when function patterns start with a slash', async () => {
|
||||
const functions = {
|
||||
'/api/test.js': { memory: 128 },
|
||||
};
|
||||
const files = ['api/test.js', '/api/test.js'];
|
||||
|
||||
const { errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).not.toBe(null);
|
||||
expect(errors[0].code).toBe('invalid_function_source');
|
||||
});
|
||||
});
|
||||
|
||||
it('Test `detectRoutes`', async () => {
|
||||
|
||||
Reference in New Issue
Block a user