Skip to content

Commit e22c702

Browse files
committed
test: fix requireFromProject tests
1 parent a32f970 commit e22c702

File tree

5 files changed

+38
-35
lines changed

5 files changed

+38
-35
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"prettier": "^2.2.1",
4141
"rimraf": "^3.0.2",
4242
"ts-jest": "^28.0.8",
43-
"typescript": "^4.9.4"
43+
"typescript": "^4.9.4",
44+
"@twilio/test-dep": "npm:[email protected]"
4445
},
4546
"lint-staged": {
4647
"*.{js,jsx,ts,tsx}": [

packages/runtime-handler/__tests__/dev-runtime/utils/requireFromProject.test.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { requireFromProject } from '../../../src/dev-runtime/utils/requireFromPr
33

44
const PROJECT_DIR = join(__dirname, '../../../../twilio-run');
55

6-
// jest.mock('../../../../twilio-run/node_modules/twilio', () => {
7-
// const x = jest.genMockFromModule('twilio');
8-
// (x as any)['__TYPE__'] = 'PROJECT_BASED';
9-
// return x;
10-
// });
6+
jest.mock('../../../../twilio-run/node_modules/@twilio/test-dep', () => {
7+
const x = jest.genMockFromModule('@twilio/test-dep');
8+
(x as any)['__TYPE__'] = 'PROJECT_BASED';
9+
return x;
10+
});
1111

12-
// jest.mock('twilio', () => {
13-
// const x = jest.genMockFromModule('twilio');
14-
// (x as any)['__TYPE__'] = 'BUILT_IN';
15-
// return x;
16-
// });
12+
jest.mock('@twilio/test-dep', () => {
13+
const x = jest.genMockFromModule('@twilio/test-dep');
14+
(x as any)['__TYPE__'] = 'BUILT_IN';
15+
return x;
16+
});
1717

1818
jest.mock(
1919
'@twilio/invalid-dependency',
@@ -26,12 +26,12 @@ jest.mock(
2626
);
2727

2828
describe('requireFromProject', () => {
29-
// test('should return project based by default', () => {
30-
// const mod = requireFromProject(PROJECT_DIR, 'twilio');
31-
// expect(mod['__TYPE__']).toBe('PROJECT_BASED');
32-
// const mod2 = require('twilio');
33-
// expect(mod2['__TYPE__']).toBe('BUILT_IN');
34-
// });
29+
test('should return project based by default', () => {
30+
const mod = requireFromProject(PROJECT_DIR, '@twilio/test-dep');
31+
expect(mod['__TYPE__']).toBe('PROJECT_BASED');
32+
const mod2 = require('@twilio/test-dep');
33+
expect(mod2['__TYPE__']).toBe('BUILT_IN');
34+
});
3535

3636
test('should fail for unknown dependency', () => {
3737
expect(() => {

packages/runtime-handler/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"npm-run-all": "^4.1.5",
5252
"rimraf": "^2.6.3",
5353
"supertest": "^3.1.0",
54-
"typescript": "^4.9.4"
54+
"typescript": "^4.9.4",
55+
"@twilio/test-dep": "npm:[email protected]"
5556
},
5657
"bugs": {
5758
"url": "https://github.com/twilio-labs/serverless-toolkit/issues"

packages/twilio-run/__tests__/utils/requireFromProject.test.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { requireFromProject } from '../../src/utils/requireFromProject';
33

44
const PROJECT_DIR = join(__dirname, '../../../runtime-handler');
55

6-
// jest.mock('../../../runtime-handler/node_modules/twilio', () => {
7-
// const x = jest.genMockFromModule('twilio');
8-
// (x as any)['__TYPE__'] = 'PROJECT_BASED';
9-
// return x;
10-
// });
6+
jest.mock('../../../runtime-handler/node_modules/@twilio/test-dep', () => {
7+
const x = jest.genMockFromModule('@twilio/test-dep');
8+
(x as any)['__TYPE__'] = 'PROJECT_BASED';
9+
return x;
10+
});
1111

12-
// jest.mock('twilio', () => {
13-
// const x = jest.genMockFromModule('twilio');
14-
// (x as any)['__TYPE__'] = 'BUILT_IN';
15-
// return x;
16-
// });
12+
jest.mock('@twilio/test-dep', () => {
13+
const x = jest.genMockFromModule('@twilio/test-dep');
14+
(x as any)['__TYPE__'] = 'BUILT_IN';
15+
return x;
16+
});
1717

1818
jest.mock(
1919
'@twilio/invalid-dependency',
@@ -26,12 +26,12 @@ jest.mock(
2626
);
2727

2828
describe('requireFromProject', () => {
29-
// test('should return project based by default', () => {
30-
// const mod = requireFromProject(PROJECT_DIR, 'twilio');
31-
// expect(mod['__TYPE__']).toBe('PROJECT_BASED');
32-
// const mod2 = require('twilio');
33-
// expect(mod2['__TYPE__']).toBe('BUILT_IN');
34-
// });
29+
test('should return project based by default', () => {
30+
const mod = requireFromProject(PROJECT_DIR, '@twilio/test-dep');
31+
expect(mod['__TYPE__']).toBe('PROJECT_BASED');
32+
const mod2 = require('@twilio/test-dep');
33+
expect(mod2['__TYPE__']).toBe('BUILT_IN');
34+
});
3535

3636
test('should fail for unknown dependency', () => {
3737
expect(() => {

packages/twilio-run/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
"mock-fs": "^5.2.0",
115115
"nock": "^12.0.2",
116116
"supertest": "^3.1.0",
117-
"typescript": "^4.9.4"
117+
"typescript": "^4.9.4",
118+
"@twilio/test-dep": "npm:[email protected]"
118119
},
119120
"files": [
120121
"bin/",

0 commit comments

Comments
 (0)