1 | var valid = require("..")
|
2 | var test = require("tap").test
|
3 | var path = require("path")
|
4 | var fs = require("fs")
|
5 |
|
6 | test("validate-npm-package-name", function (t) {
|
7 | t.deepEqual(valid("some-package"), {valid: true})
|
8 | t.deepEqual(valid("example.com"), {valid: true})
|
9 | t.deepEqual(valid("under_score"), {valid: true})
|
10 | t.deepEqual(valid("period.js"), {valid: true})
|
11 | t.deepEqual(valid("123numeric"), {valid: true})
|
12 | t.deepEqual(valid("crazy!"), {valid: true})
|
13 | t.deepEqual(valid("@npm/thingy"), {valid: true})
|
14 | t.deepEqual(valid("@npm-zors/money!time.js"), {valid: true})
|
15 |
|
16 | t.deepEqual(valid(""), {
|
17 | valid: false,
|
18 | errors: ["name length must be greater than zero"]})
|
19 |
|
20 | t.deepEqual(valid(""), {
|
21 | valid: false,
|
22 | errors: ["name length must be greater than zero"]})
|
23 |
|
24 | t.deepEqual(valid(".start-with-period"), {
|
25 | valid: false,
|
26 | errors: ["name cannot start with a period"]})
|
27 |
|
28 | t.deepEqual(valid("_start-with-underscore"), {
|
29 | valid: false,
|
30 | errors: ["name cannot start with an underscore"]})
|
31 |
|
32 | t.deepEqual(valid("contain:colons"), {
|
33 | valid: false,
|
34 | errors: ["name can only contain URL-friendly characters"]})
|
35 |
|
36 | t.deepEqual(valid("1234567890123456789012345678901234567890-more-than-fifty"), {
|
37 | valid: false,
|
38 | errors: ["name cannot be longer than 50 characters"]})
|
39 |
|
40 | t.deepEqual(valid(" leading-space"), {
|
41 | valid: false,
|
42 | errors: ["name cannot contain leading or trailing spaces", "name can only contain URL-friendly characters"]})
|
43 |
|
44 | t.deepEqual(valid("trailing-space "), {
|
45 | valid: false,
|
46 | errors: ["name cannot contain leading or trailing spaces", "name can only contain URL-friendly characters"]})
|
47 |
|
48 | t.deepEqual(valid("s/l/a/s/h/e/s"), {
|
49 | valid: false,
|
50 | errors: ["name can only contain URL-friendly characters"]})
|
51 |
|
52 | t.deepEqual(valid("node_modules"), {
|
53 | valid: false,
|
54 | errors: ["node_modules is a blacklisted name"]})
|
55 |
|
56 | t.deepEqual(valid("favicon.ico"), {
|
57 | valid: false,
|
58 | errors: ["favicon.ico is a blacklisted name"]})
|
59 |
|
60 |
|
61 |
|
62 | t.deepEqual(valid("CAPITAL-LETTERS", {allowMixedCase: true}), {valid: true})
|
63 |
|
64 | t.deepEqual(valid("CAPITAL-LETTERS"), {
|
65 | valid: false,
|
66 | errors: ["name must be lowercase"]})
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | t.end()
|
72 | })
|