Home >Web Front-end >JS Tutorial >Carrying out tests using node-plug

Carrying out tests using node-plug

Susan Sarandon
Susan SarandonOriginal
2025-01-05 13:29:40754browse

Installation

npm install node-plug

Then create a file, for example plugin.js, then create code like this

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()
  },
}*/

Then create a main.js or index.js file

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

// Menambahkan plugin
addPlugin(t)

// Menjalankan plugin
runPlugin()

// Melakukan pengujian
test(['bar'])

The code above will display:

Melakukan test menggunakan node-plug

But if:

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

// Menambahkan plugin
addPlugin(t)

// Menjalankan plugin
runPlugin()

// Melakukan pengujian
test(['foo'])

Then the test was successfully executed

Melakukan test menggunakan node-plug

The above is the detailed content of Carrying out tests using node-plug. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn