source: trip-planner-front/node_modules/validate-npm-package-name/test/index.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1'use strict'
2
3var validate = require('..')
4var test = require('tap').test
5
6test('validate-npm-package-name', function (t) {
7 // Traditional
8
9 t.deepEqual(validate('some-package'), {validForNewPackages: true, validForOldPackages: true})
10 t.deepEqual(validate('example.com'), {validForNewPackages: true, validForOldPackages: true})
11 t.deepEqual(validate('under_score'), {validForNewPackages: true, validForOldPackages: true})
12 t.deepEqual(validate('period.js'), {validForNewPackages: true, validForOldPackages: true})
13 t.deepEqual(validate('123numeric'), {validForNewPackages: true, validForOldPackages: true})
14 t.deepEqual(validate('crazy!'), {
15 validForNewPackages: false,
16 validForOldPackages: true,
17 warnings: ['name can no longer contain special characters ("~\'!()*")']
18 })
19
20 // Scoped (npm 2+)
21
22 t.deepEqual(validate('@npm/thingy'), {validForNewPackages: true, validForOldPackages: true})
23 t.deepEqual(validate('@npm-zors/money!time.js'), {
24 validForNewPackages: false,
25 validForOldPackages: true,
26 warnings: ['name can no longer contain special characters ("~\'!()*")']
27 })
28
29 // Invalid
30
31 t.deepEqual(validate(''), {
32 validForNewPackages: false,
33 validForOldPackages: false,
34 errors: ['name length must be greater than zero']})
35
36 t.deepEqual(validate(''), {
37 validForNewPackages: false,
38 validForOldPackages: false,
39 errors: ['name length must be greater than zero']})
40
41 t.deepEqual(validate('.start-with-period'), {
42 validForNewPackages: false,
43 validForOldPackages: false,
44 errors: ['name cannot start with a period']})
45
46 t.deepEqual(validate('_start-with-underscore'), {
47 validForNewPackages: false,
48 validForOldPackages: false,
49 errors: ['name cannot start with an underscore']})
50
51 t.deepEqual(validate('contain:colons'), {
52 validForNewPackages: false,
53 validForOldPackages: false,
54 errors: ['name can only contain URL-friendly characters']})
55
56 t.deepEqual(validate(' leading-space'), {
57 validForNewPackages: false,
58 validForOldPackages: false,
59 errors: ['name cannot contain leading or trailing spaces', 'name can only contain URL-friendly characters']})
60
61 t.deepEqual(validate('trailing-space '), {
62 validForNewPackages: false,
63 validForOldPackages: false,
64 errors: ['name cannot contain leading or trailing spaces', 'name can only contain URL-friendly characters']})
65
66 t.deepEqual(validate('s/l/a/s/h/e/s'), {
67 validForNewPackages: false,
68 validForOldPackages: false,
69 errors: ['name can only contain URL-friendly characters']})
70
71 t.deepEqual(validate('node_modules'), {
72 validForNewPackages: false,
73 validForOldPackages: false,
74 errors: ['node_modules is a blacklisted name']})
75
76 t.deepEqual(validate('favicon.ico'), {
77 validForNewPackages: false,
78 validForOldPackages: false,
79 errors: ['favicon.ico is a blacklisted name']})
80
81 // Node/IO Core
82
83 t.deepEqual(validate('http'), {
84 validForNewPackages: false,
85 validForOldPackages: true,
86 warnings: ['http is a core module name']})
87
88 // Long Package Names
89
90 t.deepEqual(validate('ifyouwanttogetthesumoftwonumberswherethosetwonumbersarechosenbyfindingthelargestoftwooutofthreenumbersandsquaringthemwhichismultiplyingthembyitselfthenyoushouldinputthreenumbersintothisfunctionanditwilldothatforyou-'), {
91 validForNewPackages: false,
92 validForOldPackages: true,
93 warnings: ['name can no longer contain more than 214 characters']
94 })
95
96 t.deepEqual(validate('ifyouwanttogetthesumoftwonumberswherethosetwonumbersarechosenbyfindingthelargestoftwooutofthreenumbersandsquaringthemwhichismultiplyingthembyitselfthenyoushouldinputthreenumbersintothisfunctionanditwilldothatforyou'), {
97 validForNewPackages: true,
98 validForOldPackages: true
99 })
100
101 // Legacy Mixed-Case
102
103 t.deepEqual(validate('CAPITAL-LETTERS'), {
104 validForNewPackages: false,
105 validForOldPackages: true,
106 warnings: ['name can no longer contain capital letters']})
107
108 t.end()
109})
Note: See TracBrowser for help on using the repository browser.