Skip to content

Commit

Permalink
Add test when repositories is moved
Browse files Browse the repository at this point in the history
  • Loading branch information
fiennyangeln committed Oct 10, 2018
1 parent 100b117 commit d0eab47
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions v1/lib/core/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const path = require('path');
const fs = require('fs');
const shell = require('shelljs');
const utils = require('../utils');

const blogPostWithTruncateContents = fs.readFileSync(
Expand Down Expand Up @@ -96,6 +97,36 @@ describe('utils', () => {
fs.writeFileSync(tempFilePath, 'Lorem ipsum :)');
expect(utils.getGitLastUpdated(tempFilePath)).toBeNull();
fs.unlinkSync(tempFilePath);

// test renaming and moving file
const tempFilePath2 = path.join(__dirname, '__fixtures__', '.temp2');
fs.writeFileSync(tempFilePath2, 'Lorem ipsum :)');

shell.exec(`git add ${tempFilePath2}`);
shell.exec(`git -c user.email=email@domain.fr -c user.name='Your Name'
commit -m "Create new file" --only ${tempFilePath2}`);

const createTime = utils.getGitLastUpdated(tempFilePath2);
expect(typeof createTime).toBe('string');

// rename / move the file
fs.mkdirSync(path.join(__dirname, '__fixtures__', 'test'));
const tempFilePath3 = path.join(
__dirname,
'__fixtures__',
'test',
'.temp3',
);
shell.exec(`git mv ${tempFilePath2} ${tempFilePath3}`);
shell.exec(`git -c user.email=email@domain.fr -c user.name='Your Name'
commit -m "Rename the file"`);

const lastUpdateTime = utils.getGitLastUpdated(tempFilePath3);
expect(lastUpdateTime).toEqual(createTime);

fs.unlinkSync(tempFilePath3);
fs.rmdirSync(path.join(__dirname, '__fixtures__', 'test'));
shell.exec(`git reset HEAD^^`);
});

test('idx', () => {
Expand Down

0 comments on commit d0eab47

Please sign in to comment.