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

Carrying out tests using node-plug

Susan Sarandon
Release: 2025-01-05 13:29:40
Original
725 people have browsed it

Installation

npm install node-plug
Copy after login

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

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'])
Copy after login

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'])
Copy after login

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!

source:dev.to
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template