Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(@twilio/runtime-handler): revert package.json #511

Merged
merged 3 commits into from
Mar 20, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@changesets/cli": "^2.26.0",
"@commitlint/cli": "^19.1.0",
"@commitlint/config-conventional": "^19.1.0",
"@twilio/test-dep": "npm:twilio@4.23.0",
"@twilio/test-dep": "npm:twilio@4.22.0",
"@types/jest": "^29.2.4",
"all-contributors-cli": "^6.1.2",
"commitizen": "^4.2.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { join } from 'path';
import { requireFromProject } from '../../../src/dev-runtime/utils/requireFromProject';

const PROJECT_DIR = join(__dirname, '../../../../twilio-run');
// only works if test-dep version is different from root package version
jest.mock('../../../../twilio-run/node_modules/@twilio/test-dep', () => {
const x = jest.genMockFromModule('@twilio/test-dep');
(x as any)['__TYPE__'] = 'PROJECT_BASED';
return x;
});
// jest.mock('../../../../twilio-run/node_modules/@twilio/test-dep', () => {
// const x = jest.genMockFromModule('@twilio/test-dep');
// (x as any)['__TYPE__'] = 'PROJECT_BASED';
// return x;
// });

jest.mock('@twilio/test-dep', () => {
const x = jest.genMockFromModule('@twilio/test-dep');
Expand All @@ -26,12 +25,13 @@ jest.mock(
);

describe('requireFromProject', () => {
test('should return project based by default', () => {
const mod = requireFromProject(PROJECT_DIR, '@twilio/test-dep');
expect(mod['__TYPE__']).toBe('PROJECT_BASED');
const mod2 = require('@twilio/test-dep');
expect(mod2['__TYPE__']).toBe('BUILT_IN');
});
// npm hoists the package to root node_modules making this test not possible currently
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this comments here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a reminder to uncomment it when we migrate off npm

// test('should return project based by default', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use test.skip as well ?
No need to comment everything

// const mod = requireFromProject(PROJECT_DIR, '@twilio/test-dep');
// expect(mod['__TYPE__']).toBe('PROJECT_BASED');
// const mod2 = require('@twilio/test-dep');
// expect(mod2['__TYPE__']).toBe('BUILT_IN');
// });

test('should fail for unknown dependency', () => {
expect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"build": "tsc",
"watch": "tsc --watch",
"build:noemit": "tsc --noEmit",
"clean": "rimraf ./dist ./node_modules"
"clean": "rimraf ./dist"
},
"devDependencies": {
"@twilio/test-dep": "npm:[email protected]",
Expand Down
23 changes: 12 additions & 11 deletions packages/twilio-run/__tests__/utils/requireFromProject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { requireFromProject } from '../../src/utils/requireFromProject';

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

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

jest.mock('@twilio/test-dep', () => {
const x = jest.genMockFromModule('@twilio/test-dep');
Expand All @@ -26,12 +26,13 @@ jest.mock(
);

describe('requireFromProject', () => {
test('should return project based by default', () => {
const mod = requireFromProject(PROJECT_DIR, '@twilio/test-dep');
expect(mod['__TYPE__']).toBe('PROJECT_BASED');
const mod2 = require('@twilio/test-dep');
expect(mod2['__TYPE__']).toBe('BUILT_IN');
});
// NPM hoists the package under root node_modules making this test not possible currently
// test('should return project based by default', () => {
// const mod = requireFromProject(PROJECT_DIR, '@twilio/test-dep');
// expect(mod['__TYPE__']).toBe('PROJECT_BASED');
// const mod2 = require('@twilio/test-dep');
// expect(mod2['__TYPE__']).toBe('BUILT_IN');
// });

test('should fail for unknown dependency', () => {
expect(() => {
Expand Down
Loading