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

Top comments (0)