diff --git a/.gitignore b/.gitignore index cc20735876e2..f8af4c2d13e1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ api-docs packages/*/*.tgz packages/*/dist* packages/*/package -packages/cli/test/sandbox +.sandbox diff --git a/.vscode/settings.json b/.vscode/settings.json index 8c6ff114992a..0bbe846a7e2f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,7 +14,8 @@ ".nyc_output": true, "coverage": true, "packages/*/dist": true, - "packages/*/api-docs": true + "packages/*/api-docs": true, + "**/.sandbox": true }, "files.insertFinalNewline": true, "files.trimTrailingWhitespace": true, diff --git a/packages/cli/test/clone-example.test.js b/packages/cli/test/clone-example.test.js index 0e4f404c55b8..7423bf6f6320 100644 --- a/packages/cli/test/clone-example.test.js +++ b/packages/cli/test/clone-example.test.js @@ -3,55 +3,57 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -('use strict'); +'use strict'; const promisify = require('util').promisify; const cloneExampleFromGitHub = require('../generators/example/clone-example'); const expect = require('@loopback/testlab').expect; +const fs = require('fs'); const TestSandbox = require('@loopback/testlab').TestSandbox; const glob = promisify(require('glob')); const path = require('path'); +const readFile = promisify(fs.readFile); + const VALID_EXAMPLE = 'getting-started'; -const SANDBOX_PATH = path.resolve(__dirname, 'sandbox'); +const SANDBOX_PATH = path.resolve(__dirname, '..', '.sandbox'); let sandbox; -describe.skip('cloneExampleFromGitHub (SLOW)', function() { +describe('cloneExampleFromGitHub (SLOW)', function() { this.timeout(20000); before(createSandbox); beforeEach(resetSandbox); - /** - * FIXME(kjdelisle): This test will prevent any meaningful changes from - * landing in example repositories, since it will always fail the equality - * test provided when new files are added, or when existing files are - * removed as a part of refactor/cleanup. - * - * While I do value the idea of verifying that the example packages are - * being cloned properly, we can't hang that idea on validating the - * particular presence of any content that isn't perpetually required. - * - * This test can be removed once strongloop/loopback-next#932 is complete. - */ - it('extracts all project files', () => { - return cloneExampleFromGitHub(VALID_EXAMPLE, SANDBOX_PATH) - .then(outDir => { - return Promise.all([ - glob('**', { - cwd: path.join(__dirname, `../../example-${VALID_EXAMPLE}`), - ignore: '@(node_modules|dist*|api-docs)/**', - }), - glob('**', { - cwd: outDir, - ignore: 'node_modules/**', - }), - ]); - }) - .then(found => { - const [expected, actual] = found; - expect(actual).to.deepEqual(expected); - }); + it('extracts project files', async () => { + const outDir = await cloneExampleFromGitHub(VALID_EXAMPLE, SANDBOX_PATH); + const actualFiles = await glob('**', { + cwd: outDir, + ignore: 'node_modules/**', + }); + + // We must not assume that the files downloaded from the current master + // branch are the same as the files we have in our current branch. + // By doing so, we would prevent any meaningful changes from + // landing in example repositories, since it will always fail the equality + // test provided when new files are added, or when existing files are + // removed as a part of refactor/cleanup. + expect(actualFiles).to.containDeep([ + // These files are required in all our packages, + // therefore it's safe to assume they will be always around. + 'README.md', + 'package.json', + + // We need to check a nested file to verify that directory structure + // is preserved. Hopefully `src/index.ts will be always around, + // independently on any refactorings and cleanups. + 'src/index.ts', + ]); + + const packageJson = JSON.parse(await readFile(`${outDir}/package.json`)); + expect(packageJson).to.have.properties({ + name: `@loopback/example-${VALID_EXAMPLE}`, + }); }); function createSandbox() {