From 0bd2428e6c1a5fa4f819a33ef9429d940542f786 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 7 Oct 2018 00:45:17 +0200 Subject: [PATCH] test: add scenarios where publish or access are missing (#1054) it will normalise those props are missing as emtpy arrays --- test/unit/api/config-utils.spec.js | 43 ++++++++++++++++++- .../config/yaml/pkgs-basic-no-access.yaml | 7 +++ .../config/yaml/pkgs-basic-no-proxy.yaml | 7 +++ .../config/yaml/pkgs-basic-no-publish.yaml | 7 +++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 test/unit/partials/config/yaml/pkgs-basic-no-access.yaml create mode 100644 test/unit/partials/config/yaml/pkgs-basic-no-proxy.yaml create mode 100644 test/unit/partials/config/yaml/pkgs-basic-no-publish.yaml diff --git a/test/unit/api/config-utils.spec.js b/test/unit/api/config-utils.spec.js index 8267738b8..ab5ef1bb9 100644 --- a/test/unit/api/config-utils.spec.js +++ b/test/unit/api/config-utils.spec.js @@ -60,7 +60,46 @@ describe('Config Utilities', () => { expect(all).toBeDefined(); }); - test('should test multi group', ()=> { + test('should define an empty publish array even if is not defined in packages', ()=> { + const {packages} = parseConfigFile(parseConfigurationFile('pkgs-basic-no-publish')); + const access = normalisePackageAccess(packages); + + const scoped = access[`${PACKAGE_ACCESS.SCOPE}`]; + const all = access[`${PACKAGE_ACCESS.ALL}`]; + // publish must defined + expect(scoped.publish).toBeDefined(); + expect(scoped.publish).toHaveLength(0); + expect(all.publish).toBeDefined(); + expect(all.publish).toHaveLength(0); + }); + + test('should define an empty access array even if is not defined in packages', ()=> { + const {packages} = parseConfigFile(parseConfigurationFile('pkgs-basic-no-access')); + const access = normalisePackageAccess(packages); + + const scoped = access[`${PACKAGE_ACCESS.SCOPE}`]; + const all = access[`${PACKAGE_ACCESS.ALL}`]; + // publish must defined + expect(scoped.access).toBeDefined(); + expect(scoped.access).toHaveLength(0); + expect(all.access).toBeDefined(); + expect(all.access).toHaveLength(0); + }); + + test('should define an empty proxy array even if is not defined in package', ()=> { + const {packages} = parseConfigFile(parseConfigurationFile('pkgs-basic-no-proxy')); + const access = normalisePackageAccess(packages); + + const scoped = access[`${PACKAGE_ACCESS.SCOPE}`]; + const all = access[`${PACKAGE_ACCESS.ALL}`]; + // publish must defined + expect(scoped.proxy).toBeDefined(); + expect(scoped.proxy).toHaveLength(0); + expect(all.proxy).toBeDefined(); + expect(all.proxy).toHaveLength(0); + }); + + test('should test multi user group definition', ()=> { const {packages} = parseConfigFile(parseConfigurationFile('pkgs-multi-group')); const access = normalisePackageAccess(packages); @@ -84,7 +123,7 @@ describe('Config Utilities', () => { }); - test('should deprecated packages props', ()=> { + test('should normalize deprecated packages into the new ones (backward props compatible)', ()=> { const {packages} = parseConfigFile(parseConfigurationFile('deprecated-pkgs-basic')); const access = normalisePackageAccess(packages); diff --git a/test/unit/partials/config/yaml/pkgs-basic-no-access.yaml b/test/unit/partials/config/yaml/pkgs-basic-no-access.yaml new file mode 100644 index 000000000..9ba1d7233 --- /dev/null +++ b/test/unit/partials/config/yaml/pkgs-basic-no-access.yaml @@ -0,0 +1,7 @@ +packages: + '@*/*': + publish: $all + proxy: npmjs + '**': + publish: $all + proxy: npmjs diff --git a/test/unit/partials/config/yaml/pkgs-basic-no-proxy.yaml b/test/unit/partials/config/yaml/pkgs-basic-no-proxy.yaml new file mode 100644 index 000000000..213bc9813 --- /dev/null +++ b/test/unit/partials/config/yaml/pkgs-basic-no-proxy.yaml @@ -0,0 +1,7 @@ +packages: + '@*/*': + access: $all + publish: $all + '**': + access: $all + publish: $all diff --git a/test/unit/partials/config/yaml/pkgs-basic-no-publish.yaml b/test/unit/partials/config/yaml/pkgs-basic-no-publish.yaml new file mode 100644 index 000000000..204f26d05 --- /dev/null +++ b/test/unit/partials/config/yaml/pkgs-basic-no-publish.yaml @@ -0,0 +1,7 @@ +packages: + '@*/*': + access: $all + proxy: npmjs + '**': + access: $all + proxy: npmjs