Skip to content

Commit

Permalink
refactor: remove scan vue files
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jan 5, 2020
1 parent 82b6dd9 commit 28dd9ce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ connection.onInitialize(
storageService = new StorageService();
scannerService = new ScannerService(storageService, settings);

const files = await findFiles('**/*.{scss,vue}', {
const files = await findFiles('**/*.scss', {
cwd: params.rootPath,
deep: settings.scannerDepth,
ignore: settings.scannerExclude
Expand Down
8 changes: 1 addition & 7 deletions src/services/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ISettings } from '../types/settings';
import { readFile, fileExists } from '../utils/fs';
import { parseDocument } from './parser';
import StorageService from './storage';
import { isVueFile, getVueSCSSContent } from '../utils/vue';

export default class ScannerService {
constructor(private readonly _storage: StorageService, private readonly _settings: ISettings) {}
Expand Down Expand Up @@ -38,12 +37,7 @@ export default class ScannerService {
}

const content = await this._readFile(filepath);
const document = TextDocument.create(
originalFilepath,
'scss',
1,
isVueFile(filepath) ? getVueSCSSContent(content) : content
);
const document = TextDocument.create(originalFilepath, 'scss', 1, content);
const { symbols } = parseDocument(document, null);

this._storage.set(filepath, { ...symbols, filepath });
Expand Down
56 changes: 4 additions & 52 deletions src/test/services/scanner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ describe('Services/Scanner', () => {
scanner.fileExistsStub.resolves(true);
scanner.readFileStub.onFirstCall().resolves('$name: value;');
scanner.readFileStub.onSecondCall().resolves('');
scanner.readFileStub.onThirdCall().resolves('');

await scanner.scan(['index.scss', 'variables.scss', 'AppButton.vue']);
await scanner.scan(['index.scss', 'variables.scss']);

assert.deepStrictEqual(storage.keys(), ['index.scss', 'variables.scss', 'AppButton.vue']);
assert.deepStrictEqual(storage.keys(), ['index.scss', 'variables.scss']);
assert.ok(storage.get('index.scss'));
assert.strictEqual(storage.get('index.scss').variables.length, 1);

assert.strictEqual(scanner.fileExistsStub.callCount, 3);
assert.strictEqual(scanner.readFileStub.callCount, 3);
assert.strictEqual(scanner.fileExistsStub.callCount, 2);
assert.strictEqual(scanner.readFileStub.callCount, 2);
});

it('should find file and imported files', async () => {
Expand All @@ -60,30 +59,6 @@ describe('Services/Scanner', () => {
assert.strictEqual(scanner.readFileStub.callCount, 2);
});

it('should find vue file and imported scss files', async () => {
const storage = new StorageService();
const settings = helpers.makeSettings();
const scanner = new ScannerServiceTest(storage, settings);

scanner.fileExistsStub.resolves(true);
scanner.readFileStub.onFirstCall().resolves(`
<template>
<button>@import "mixin.scss";</button>
</template>
<style lang="scss">
@import "variables.scss";
</style>`);
scanner.readFileStub.onSecondCall().resolves('');
scanner.readFileStub.onThirdCall().resolves('');

await scanner.scan(['AppButton.vue']);

assert.deepStrictEqual(storage.keys(), ['AppButton.vue', 'variables.scss']);

assert.strictEqual(scanner.fileExistsStub.callCount, 2);
assert.strictEqual(scanner.readFileStub.callCount, 2);
});

it('should do not find imported files when it not required', async () => {
const storage = new StorageService();
const settings = helpers.makeSettings({ scanImportedFiles: false });
Expand All @@ -101,29 +76,6 @@ describe('Services/Scanner', () => {
assert.strictEqual(scanner.readFileStub.callCount, 1);
});

it('should vue file do not find imported files when it not required', async () => {
const storage = new StorageService();
const settings = helpers.makeSettings({ scanImportedFiles: false });
const scanner = new ScannerServiceTest(storage, settings);

scanner.fileExistsStub.resolves(true);
scanner.readFileStub.onFirstCall().resolves(`
<template>
<button>@import "mixin.scss";</button>
</template>
<style lang="scss">
@import "variables.scss";
</style>`);
scanner.readFileStub.onSecondCall().resolves('');

await scanner.scan(['AppButton.vue']);

assert.deepStrictEqual(storage.keys(), ['AppButton.vue']);

assert.strictEqual(scanner.fileExistsStub.callCount, 1);
assert.strictEqual(scanner.readFileStub.callCount, 1);
});

it('should do not find imported files when the recursive mode is no required', async () => {
const storage = new StorageService();
const settings = helpers.makeSettings();
Expand Down

0 comments on commit 28dd9ce

Please sign in to comment.