我想允许用户将JavaScript代码编写为有角度的形式,并对该代码运行一些mocha / chai测试。...我正在寻找相关的想法...我应该从中解析代码吗?形式将字符串传递给函数?请提出任何想法...任何回购协议都已经做到了...
用户应该能够编写执行某些任务的javascript函数,然后应用程序应对此进行运行测试,以确保表单中输入的javascript能够完成我们要求的任务...
let userIDResponse = """
{\"user_id\":\"5a7ab957a225856b38f49bb4\"}
"""
let tokenResponse = """
{\"access_token\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6IjczMUE3OUEyMjY3QjY4Q0EwNTc5QjYzRjdFMkY0QjlBQkZFMENEMTUiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJjeHA1b2laN2FNb0ZlYllfZmk5TG1yX2d6UlUifQ.eyJuYmYiOjE1MTI5NjU3NTgsImV4cCI6MTUxMjk2OTM1OCwiaXNzIjoiaHR0cHM6Ly9pZG0uYWxwaGFub3ZhLnNnIiwiYXVkIjpbImh0dHBzOi8vaWRtLmFscGhhbm92YS5zZy9yZXNvdXJjZXMiLCJhcGkyIl0sImNsaWVudF9pZCI6ImNhcGFwb3QtbmciLCJzdWIiOiI1YTFjMWU5MjY0MjUzYjFlMWU2N2ZhZDIiLCJhdXRoX3RpbWUiOjE1MTI5NjU3NTgsImlkcCI6ImFscGhhbm92YSIsImZpcnN0X25hbWUiOiJTdGV2ZW4iLCJsYXN0X25hbWUiOiJDdXJ0aXMiLCJuYW1lIjoiU3RldmVuIEN1cnRpcyIsImVtYWlsIjoic3RldmVuQGFscGhhbm92YS5zZyIsInNjb3BlIjpbImNhcGFwb3QucHJvZmlsZSIsImVtYWlsIiwib3BlbmlkIiwiYXBpMi5yZWFkX29ubHkiLCJvZmZsaW5lX2FjY2VzcyJdLCJhbXIiOlsicGFzc3dvcmQiXX0.q4-SF5KBVSwN4bFhcQ88icR9X2jzz_JH2K4EpDgS-oZjjppNruckxfTjauVqcwG8zPR0eGzx5CBXiAfMeg9akShWajqBZ9rkCsqjXw6Ef74J9cTBDhxTEUL0v7P0zm_fVNOutM_UJQ-DiQr2gAO0mfAxMhOiQ_uXlKoM2RYGKjfMkH6Ym7kBjtRAhho8pPVmtQiBmVFI5OUVXNU3rPVgB7sx-I1LZmUZBZoy7T4s14TAuE4yiUyTBgO5joyRsZtMdFybna8CRK_ylS3WC6wOBNm74O9IrZlbsiradtLzMG-9E8AnjbvH4RYR68H2xpt562PfnGD_VC9NXFQ7iRrRMw\"}
"""
答案 0 :(得分:2)
我宁愿建议搜索现有模块/库,这些模块/库可提供开发自己的代码编辑器的功能。
首先,您可以检查以下两个参考。
使用ace代码编辑器的文章 https://medium.com/@ofir3322/create-an-online-ide-with-angular-6-nodejs-part-1-163a939a7929
摩纳哥编辑器(支持Microsoft VS Code) https://microsoft.github.io/monaco-editor/
摩纳哥编辑器的节点模块 https://www.npmjs.com/package/ngx-monaco-editor
单元测试运行时
然后检查诸如mocha之类的框架,这些框架使您能够在运行时进行单元测试代码。
https://github.com/mochajs/mocha/wiki/Using-Mocha-programmatically