source: frontend/node_modules/node-exports-info/test/getCategoryFlags.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.5 KB
Line 
1'use strict';
2
3var test = require('tape');
4var forEach = require('for-each');
5
6var getCategoryFlags = require('../getCategoryFlags');
7var getRangePairs = require('../getRangePairs');
8
9test('getCategoryFlags', function (t) {
10 t['throws'](
11 // @ts-expect-error
12 function () { getCategoryFlags('not a category'); },
13 RangeError,
14 'invalid category throws'
15 );
16
17 forEach(getRangePairs(), function (pair) {
18 var category = pair[1];
19 t.test('category: ' + category, function (st) {
20 var flags = getCategoryFlags(category);
21
22 st.ok(
23 flags && typeof flags === 'object',
24 'returns an object'
25 );
26 st.ok(
27 'patterns' in flags && typeof flags.patterns === 'boolean',
28 'has boolean patterns flag'
29 );
30 st.ok(
31 'patternTrailers' in flags && typeof flags.patternTrailers === 'boolean',
32 'has boolean patternTrailers flag'
33 );
34 st.ok(
35 'dirSlash' in flags && typeof flags.dirSlash === 'boolean',
36 'has boolean dirSlash flag'
37 );
38
39 // Verify flag consistency: patternTrailers implies patterns
40 if (flags.patternTrailers) {
41 st.ok(flags.patterns, 'patternTrailers implies patterns');
42 }
43
44 st.end();
45 });
46 });
47
48 t.test('specific category flags', function (st) {
49 st.deepEqual(
50 getCategoryFlags('pre-exports'),
51 { patterns: false, patternTrailers: false, dirSlash: false },
52 'pre-exports has no flags'
53 );
54
55 st.deepEqual(
56 getCategoryFlags('broken'),
57 { patterns: false, patternTrailers: false, dirSlash: false },
58 'broken has no flags'
59 );
60
61 st.deepEqual(
62 getCategoryFlags('experimental'),
63 { patterns: false, patternTrailers: false, dirSlash: false },
64 'experimental has no flags'
65 );
66
67 st.deepEqual(
68 getCategoryFlags('conditions'),
69 { patterns: false, patternTrailers: false, dirSlash: false },
70 'conditions has no flags'
71 );
72
73 st.deepEqual(
74 getCategoryFlags('broken-dir-slash-conditions'),
75 { patterns: false, patternTrailers: false, dirSlash: true },
76 'broken-dir-slash-conditions has dirSlash'
77 );
78
79 st.deepEqual(
80 getCategoryFlags('patterns'),
81 { patterns: true, patternTrailers: false, dirSlash: true },
82 'patterns has patterns and dirSlash'
83 );
84
85 st.deepEqual(
86 getCategoryFlags('pattern-trailers'),
87 { patterns: true, patternTrailers: true, dirSlash: true },
88 'pattern-trailers has all flags'
89 );
90
91 st.deepEqual(
92 getCategoryFlags('pattern-trailers+json-imports'),
93 { patterns: true, patternTrailers: true, dirSlash: true },
94 'pattern-trailers+json-imports has all flags'
95 );
96
97 st.deepEqual(
98 getCategoryFlags('pattern-trailers-no-dir-slash'),
99 { patterns: true, patternTrailers: true, dirSlash: false },
100 'pattern-trailers-no-dir-slash has patterns and patternTrailers but not dirSlash'
101 );
102
103 st.deepEqual(
104 getCategoryFlags('pattern-trailers-no-dir-slash+json-imports'),
105 { patterns: true, patternTrailers: true, dirSlash: false },
106 'pattern-trailers-no-dir-slash+json-imports has patterns and patternTrailers but not dirSlash'
107 );
108
109 st.deepEqual(
110 getCategoryFlags('require-esm'),
111 { patterns: true, patternTrailers: true, dirSlash: false },
112 'require-esm has patterns and patternTrailers but not dirSlash'
113 );
114
115 st.deepEqual(
116 getCategoryFlags('strips-types'),
117 { patterns: true, patternTrailers: true, dirSlash: false },
118 'strips-types has patterns and patternTrailers but not dirSlash'
119 );
120
121 st.deepEqual(
122 getCategoryFlags('subpath-imports-slash'),
123 { patterns: true, patternTrailers: true, dirSlash: true },
124 'subpath-imports-slash has all flags'
125 );
126
127 st.end();
128 });
129
130 t.end();
131});
Note: See TracBrowser for help on using the repository browser.