Get the App
SLTechnology News&Howtos  ›  Development  › 

What is JavaScript's code style checking tool node jscs?

Shulou Source: shulou.com Published: 2022-06-03 08:13:39 10月14日 Update

JavaScript code style check tool node jscs is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Node-jscs is a code style checking tool for JavaScript. It can be used in Node.js and browsers, using the following methods in browsers.

Methods used by node-jscs

Varchecker=newJscsStringChecker ()

Checker.registerDefaultRules ()

Checker.configure ({disallowMultipleVarDecl:true})

Varerrors=checker.checkString ('varx,y=1;')

Errors.getErrorList () .forEach (function (error) {

Console.log (errors.explainError (error))

})

Detect node-jscs

First of all, you need to install the nodejs development environment to detect nodejs. At present, the front-end unit tests only cover the logical content (environment) in js.

Unit testing

The front-end node.js uses jest for unit testing.

Install the jest environment

Install jest

Cdxxxx# goes to the root directory of the project file

Npmi# needs to be installed to the root directory of the project

When npmruntest# is installed in this way, you need to use this command to run jest

one

two

three

Install jest (2)

Npminstall-gyarn# installs yarn, which may cause permission problems and add sudo.

Yarn--version# verifies yarn

Cdxxxx# goes to the root directory of the project file

Yarnadd--devjest# installation jest# needs to be installed to the root directory of the project

Yarntest# runs all the tests of the project

Yarntestxxx# runs the project specified folder test

one

two

three

four

five

six

Unit test coverage

Use npmruntest

Npmruntest--coverage# can see the coverage on the terminal.

one

Use yarntest

Yarntest--coverage# can see the coverage on the terminal.

Yarnjest--coverage# can see the coverage on the terminal.

one

two

Coverage index

% stmts is statement coverage (statementcoverage): is every statement executed?

% Branch branch coverage (brabchcoverahe): is every if block executed?

% Funcs function coverage (functioncoverage): is every function called?

% Lines line coverage (linecoverage): is every line executed?

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Coverage project test unit available in root directory code file environment terminal run tool style check content function front end method browser statement Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Redmi Xiaomi Shulou Information