DEV Community

Salman
Salman

Posted on

Melakukan test menggunakan node-plug

Instalasi

npm install node-plug
Enter fullscreen mode Exit fullscreen mode

Lalu buat file misalnya plugin.js setelah itu buat kode seperti ini

export const t = {
  async run() {
    await console.log('foo')
  },
}

// atau
/*const test = 'foo'

export const t = {
  async run() {
    await console.log(test)
  },
}*/

// atau
/*const test = {
  run() {
    console.log('foo')
  },
}

export const t = {
  async run() {
    await test.run()
  },
}*/
Enter fullscreen mode Exit fullscreen mode

Lalu buat file main.js atau index.js

import { addPlugin, runPlugin, test } from 'node-plug'
import { t } from './plugin.js'

// Menambahkan plugin
addPlugin(t)

// Menjalankan plugin
runPlugin()

// Melakukan pengujian
test(['bar'])
Enter fullscreen mode Exit fullscreen mode

Kode di atas akan menampilkan:

Image description

Tapi jika:

import { addPlugin, runPlugin, test } from 'node-plug'
import { t } from './plugin.js'

// Menambahkan plugin
addPlugin(t)

// Menjalankan plugin
runPlugin()

// Melakukan pengujian
test(['foo'])
Enter fullscreen mode Exit fullscreen mode

Maka pengujian berhasil dijalankan

Image description

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more