{"id":52560,"date":"2024-12-03T17:29:13","date_gmt":"2024-12-03T09:29:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52560\/"},"modified":"2024-12-03T17:29:13","modified_gmt":"2024-12-03T09:29:13","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e6%88%91%e7%9a%84-node-js-%e4%bb%a3%e7%a0%81%e6%97%a0%e6%b3%95%e7%94%a8-require-%e5%bc%95%e5%85%a5-chai%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52560\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732180541673efa3de7117.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e3a\u4f55\u5728 Chai \u7684\u5b9e\u9645\u4f7f\u7528\u4e2d\u65e0\u6cd5\u4f7f\u7528 require \u5f15\u5165\uff1f<\/strong><\/p>\n<p>\u67d0\u4e9b\u5f00\u6e90\u4ee3\u7801\u4e2d\u4f7f\u7528 require \u5f15\u5165 Chai \u5e93\uff0c\u4f8b\u5982 GitHub \u4e0a tree-sitter\/node-tree-sitter \u4e2d\u7684\u4ee3\u7801\u3002\u7136\u800c\uff0c\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u5374\u65e0\u6cd5\u901a\u8fc7 require \u5728 Node.js \u4ee3\u7801\u4e2d\u5f15\u5165 Chai\u3002<\/p>\n<p>\u4e4b\u6240\u4ee5\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u662f\u56e0\u4e3a JavaScript \u4e2d\u5b58\u5728\u4e24\u79cd\u6a21\u5757\u5f15\u5165\u65b9\u5f0f\uff1aCommonJS \u6a21\u5757\u548c ES6 \u6a21\u5757\u3002require \u7528\u4e8e\u5f15\u5165 CommonJS \u6a21\u5757\uff0c\u800c ES6 \u6a21\u5757\u5219\u9700\u8981\u901a\u8fc7 import \u8bed\u6cd5\u5f15\u5165\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 require \u65e0\u6cd5\u5f15\u5165 ES6 \u6a21\u5757\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002<\/p>\n<p>\u5728 Chai \u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u65e0\u6cd5\u901a\u8fc7 require \u5f15\u5165\uff0c\u662f\u56e0\u4e3a\u4f60\u6b63\u5728\u8bd5\u56fe\u4f7f\u7528 require \u5f15\u5165 ES6 \u6a21\u5757\u3002\u89e3\u51b3\u65b9\u6cd5\u6709\u4e24\u79cd\uff1a<\/p>\n<ol>\n<li>\u5c06 require \u66ff\u6362\u4e3a ES6 \u7684 import \u8bed\u6cd5\u3002<\/li>\n<li>\u5f15\u5165 CommonJS \u683c\u5f0f\u7684 Chai \u6a21\u5757\u3002<\/li>\n<\/ol>\n<p>\u67d0\u4e9b\u7b2c\u4e09\u65b9\u5e93\u63d0\u4f9b\u4e86\u4e24\u79cd\u683c\u5f0f\u7684\u6a21\u5757\uff0c\u5373\u65e7\u7248\u672c\u7684 CommonJS \u6a21\u5757\u548c\u65b0\u7248\u672c\u7684 ES6 \u6a21\u5757\u3002\u901a\u8fc7\u66f4\u6539 require \u548c import \u7684\u4f7f\u7528\u65b9\u5f0f\u6216\u5f15\u5165\u6b63\u786e\u7684\u6a21\u5757\u683c\u5f0f\uff0c\u5373\u53ef\u89e3\u51b3\u65e0\u6cd5\u5728 Node.js \u4ee3\u7801\u4e2d\u5f15\u5165 Chai \u7684\u95ee\u9898\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   DIY\u6512\u673a\u53bb\u7535\u8111\u57ce\u8fd8\u662f\u4eac\u4e1c\uff1f\u82cf\u5b81\uff1f\u6dd8\u5b9d\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f \u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u4e3a\u4ec0\u4e48\u6211\u7684 Node.js \u4ee3\u7801\u65e0\u6cd5\u7528 require \u5f15\u5165 Chai\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01 \u4e3a\u4f55\u5728 Chai \u7684\u5b9e\u9645\u4f7f\u7528\u4e2d\u65e0\u6cd5\u4f7f\u7528 require \u5f15\u5165\uff1f \u67d0\u4e9b\u5f00\u6e90\u4ee3\u7801\u4e2d\u4f7f\u7528 require \u5f15\u5165 Chai \u5e93\uff0c\u4f8b\u5982 GitHub \u4e0a tree-sitter\/node-tree-sitter \u4e2d\u7684\u4ee3\u7801\u3002\u7136\u800c\uff0c\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u5374\u65e0\u6cd5\u901a\u8fc7 require \u5728 Node.js \u4ee3\u7801\u4e2d\u5f15\u5165 Chai\u3002 \u4e4b\u6240\u4ee5\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u662f\u56e0\u4e3a JavaScript \u4e2d\u5b58\u5728\u4e24\u79cd\u6a21\u5757\u5f15\u5165\u65b9\u5f0f\uff1aCommonJS \u6a21\u5757\u548c ES6 \u6a21\u5757\u3002require \u7528\u4e8e\u5f15\u5165 CommonJS \u6a21\u5757\uff0c\u800c ES6 \u6a21\u5757\u5219\u9700\u8981\u901a\u8fc7 import \u8bed\u6cd5\u5f15\u5165\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 require \u65e0\u6cd5\u5f15\u5165 ES6 \u6a21\u5757\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002 \u5728 Chai \u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u65e0\u6cd5\u901a\u8fc7 require \u5f15\u5165\uff0c\u662f\u56e0\u4e3a\u4f60\u6b63\u5728\u8bd5\u56fe\u4f7f\u7528 require \u5f15\u5165 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52560","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52560"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52560\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}