| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var test = require('tape');
|
|---|
| 4 | var forEach = require('for-each');
|
|---|
| 5 |
|
|---|
| 6 | var getCategoryInfo = require('../getCategoryInfo');
|
|---|
| 7 | var getCategoryFlags = require('../getCategoryFlags');
|
|---|
| 8 | var getConditionsForCategory = require('../getConditionsForCategory');
|
|---|
| 9 | var getRangePairs = require('../getRangePairs');
|
|---|
| 10 |
|
|---|
| 11 | test('getCategoryInfo', function (t) {
|
|---|
| 12 | t['throws'](
|
|---|
| 13 | // @ts-expect-error
|
|---|
| 14 | function () { getCategoryInfo('not a category'); },
|
|---|
| 15 | RangeError,
|
|---|
| 16 | 'invalid category throws'
|
|---|
| 17 | );
|
|---|
| 18 |
|
|---|
| 19 | forEach(getRangePairs(), function (pair) {
|
|---|
| 20 | var category = pair[1];
|
|---|
| 21 | t.test('category: ' + category, function (st) {
|
|---|
| 22 | var info = getCategoryInfo(category);
|
|---|
| 23 |
|
|---|
| 24 | st.ok(
|
|---|
| 25 | info && typeof info === 'object',
|
|---|
| 26 | 'returns an object'
|
|---|
| 27 | );
|
|---|
| 28 | st.ok(
|
|---|
| 29 | 'conditions' in info,
|
|---|
| 30 | 'has conditions property'
|
|---|
| 31 | );
|
|---|
| 32 | st.ok(
|
|---|
| 33 | 'flags' in info && info.flags && typeof info.flags === 'object',
|
|---|
| 34 | 'has flags object'
|
|---|
| 35 | );
|
|---|
| 36 |
|
|---|
| 37 | // Verify it matches individual function results
|
|---|
| 38 | st.deepEqual(
|
|---|
| 39 | info.conditions,
|
|---|
| 40 | getConditionsForCategory(category, 'require'),
|
|---|
| 41 | 'conditions match getConditionsForCategory with require'
|
|---|
| 42 | );
|
|---|
| 43 | st.deepEqual(
|
|---|
| 44 | info.flags,
|
|---|
| 45 | getCategoryFlags(category),
|
|---|
| 46 | 'flags match getCategoryFlags'
|
|---|
| 47 | );
|
|---|
| 48 |
|
|---|
| 49 | // Test with explicit moduleSystem
|
|---|
| 50 | var importInfo = getCategoryInfo(category, 'import');
|
|---|
| 51 | st.deepEqual(
|
|---|
| 52 | importInfo.conditions,
|
|---|
| 53 | getConditionsForCategory(category, 'import'),
|
|---|
| 54 | 'import conditions match getConditionsForCategory with import'
|
|---|
| 55 | );
|
|---|
| 56 |
|
|---|
| 57 | var requireInfo = getCategoryInfo(category, 'require');
|
|---|
| 58 | st.deepEqual(
|
|---|
| 59 | requireInfo.conditions,
|
|---|
| 60 | getConditionsForCategory(category, 'require'),
|
|---|
| 61 | 'require conditions match getConditionsForCategory with require'
|
|---|
| 62 | );
|
|---|
| 63 |
|
|---|
| 64 | st.end();
|
|---|
| 65 | });
|
|---|
| 66 | });
|
|---|
| 67 |
|
|---|
| 68 | t.end();
|
|---|
| 69 | });
|
|---|