Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Latest commit

 

History

History
169 lines (131 loc) · 4.64 KB

README.ja.md

File metadata and controls

169 lines (131 loc) · 4.64 KB

clasp tested by ts-mocha JavaScript Style Guide

English - 日本語

GASUnit

banner

Google Apps Script用のテストライブラリ。
結果はロガーに記録されるか、Slackに投稿されます。

使い方

ライブラリを追加

プロジェクトキー:MSnMmw8hLWgjUG6uKSTQBEzVZgzu5bsVr

テストを書く

テストを書くために、 Exports スタイルを使用できます(今のところは)。

Exportsスタイル

Exportsスタイルは、Mochaにインスパイアされています。

ロガーを使用:

var exports = GASUnit.exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

Slackを使用:

var WEBHOOK_URL = 'https://...'
var exports = GASUnit.slack(WEBHOOK_URL).exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

ソースコードを公開する場合、webhook urlをリテラルとして書かないでください。
プロパティを環境変数として使用できます。

var WEBHOOK_URL = PropertiesService.getScriptProperties().getProperty('WEBHOOK_URL')
var exports = GASUnit.slack(WEBHOOK_URL).exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

あるいは、次のように書いてもいいでしょう。

var WEBHOOK_URL = PropertiesService.getScriptProperties().getProperty('WEBHOOK_URL')
var exports = WEBHOOK_URL ? GASUnit.slack(WEBHOOK_URL).exports : GASUnit.exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

テストを実行

ブラウザ上でテスト関数を実行します。

.doc/run_test.png

結果を見る

ロガー

成功:

.doc/logger_success.png

失敗:

.doc/logger_fail.png

Slack

成功:

.doc/slack_success.png

失敗:

.doc/slack_fail.png

アサーション

GASUnitは、値がtruthyかどうかを検証するという最小限のアサート関数を提供しています。
任意の(Google Apps Script用の)アサーションライブラリを使用できます。
GASUnitは、公式アサーションライブラリとしてAssertGASも提供しています。

バッジ

プロジェクトでGASUnitを使用していることを示すために、バッジを使用できます。

tested by GASUnit

Markdown:

[![tested by GASUnit](https://img.shields.io/badge/tested%20by-GASUnit-%234285F1)](https://github.com/gasunit/GASUnit)

HTML:

<a href="https://github.com/gasunit/GASUnit"><img src="https://img.shields.io/badge/tested%20by-GASUnit-%234285F1" alt="tested by GASUnit"></a>

開発

package.jsonを参照してください。

gasunit/exampleを参照してください。

記事

日本語