跳到主要內容

發表文章

十分鐘搞懂Node.js Unit Test (單元測試), 使用 Mocha 和 Chai

前言 基本上Unit test的好處多多, 我們可以專注在新開發的功能上測試, 而不用浪費時間測到一些不相關的部分, 除此之外, 將來在除錯時也容易找到問題 目前有許多套件可以輔助我們做Unit test, 今天著重在如何使用 mocha , chai   建立Test資料夾, 檔案結構如下  /node_modures app.js package.json /test 下載mocha, chai $ npm install mocha --save-dev $ npm install chai --save-dev 修改package.json 加入以下設定 "scripts" : {  "test": " mocha    --exit"   }, --exit 這個flag的作用是, 讓mocha執行完測試後可以自動結束, 這個flag可加也可以不加, 不加的話有可能在跑CICD的Pipeline時會被mocha給卡住 當我們使用npm test 的時候, 就會把 mocha 模組叫起來做單元測試 改完之後的package.json如下: { "name": "my-simple-test", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "mocha --exit" }, ...    test.js 在/test資料夾下建立test.js, 此時檔案架構如下 /node_modures app.js package.json /test test.js 我們可以想要測的部分寫在 it 的 callback function裡, 然後再使用assert去比對結果是否符合預期 開始測試  $ ...

How to change the screen resolution over a remote session

This article shows how to change the screen resolution from a remote session. Step 1. Click the Show options Step 2. Click the Display option. As you can see, you can adjust the screen resolution in Display configuration

How to Reinstall Ubuntu on Window 10

Step 1. Uninstall ubuntu Open Command Prompt (Or Window PowerShell) and type > lxrun /uninstall Type "y" to continue: y If you'd like to completely uninstall Ubuntu that including user account information, you can use /full option > lxrun /uninstall /full Step 2. Install Ubuntu Type bash on Cortana search bar and click "bash" After that, you will see the message like "This will install Ubuntu on Windows, distributed by Canonical ..."

如何設定VM的網路(Hyper V)

在我們架好VM, 灌好OS之後, 或許會想要讓VM可以聯網去更新套件, 或者是下載Python, Node JS 等等, 以下的幾個步驟設定完之後, 就可以讓VM聯網了 首先, 打開Virtual Switch Manager 接下來, 點選 Create Virtual Network 最後按OK 套用你剛剛建立的Virtual Switch到VM,

[Bot Framework] How to reply an image

There are 2 ways to achieve that goal. First one, pass image url to channel if my source url is like http://abc.com/dog.png                var reply = context.MakeMessage();                                reply.Attachments.Add(new Attachment                 {                     ContentUrl = $" http://abc.com/dog.png ",                     ContentType = "image/png",                 }); Pass base64 encoded image data                 Stream fs = File.OpenRead("C:\\dog.png");                 byte[] img = fs.ToArray();        ...

在Azure SQL上新增使用者

實務上, 當我們開放資料庫給其他人存取時, 通常不會給管理者帳密讓他們去連資料庫, 而是新增一個新User並給予適當的權限, 以下就是實作步驟 首先, 建立一個帳號用來登陸SQL Server (這個SQL語法必須對master資料庫執行) CREATE LOGIN [abotuserlogin] WITH PASSWORD ='ooo12345678' GO 替master新增使用者 CREATE USER [aauser] FOR LOGIN [abotuserlogin]  GO 針對要開放的資料庫新增使用者 在Object Explorer上右鍵你想要動的資料庫 CREATE USER [aauser] FOR LOGIN [abotuserlogin]  GO 有了使用者之後我們就可以來設定權限 基本上有兩種方法 設定Role(通常一個Role就包含數個權限) 直接調整權限 總共有底下這麼多權限可以使用 若只想要開放資料的增刪修查, 那可以增加db_datareader, db_datawrite這兩個Role EXEC sp_addrolemember 'db_datareader', [aauser]; GO EXEC sp_addrolemember 'db_datawriter', [aauser]; GO 注意: 上面給的權限只能用來處理資料, 所以如果要加Table或是砍Table的話, 會出現access denied 的喔 最後, 如果這個User用不到了, 想要刪除的話, 可以Security 下找到我們剛剛加的 abotuserlogin 還有我們剛剛新增的aauser 右鍵這些名稱, 我個就可以看到刪除選項 Ref: https://azure.microsoft.com/en-us/blog/adding-users-to-your-sql-azure-database/ https://...