Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ api-docs
packages/*/*.tgz
packages/*/dist*
packages/*/package
packages/cli/test/sandbox
.sandbox
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
68 changes: 35 additions & 33 deletions packages/cli/test/clone-example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the word function and use describe('cloneExampleFromGitHub (SLOW)', () => { to be consistent with the code base.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot - the next line is calling this.timeout(). This is one of the gotchas of using arrow functions with Mocha.

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() {
Expand Down